cleaned up code
This commit is contained in:
parent
a41c9f4b30
commit
04170eb886
@ -13,9 +13,6 @@ class Modal: GKEntity{
|
|||||||
var unitCount:Int
|
var unitCount:Int
|
||||||
|
|
||||||
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
|
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
|
||||||
if currentDraggedBase == nil{
|
|
||||||
print("nil")
|
|
||||||
}
|
|
||||||
unitCount = base.unitCount
|
unitCount = base.unitCount
|
||||||
super.init()
|
super.init()
|
||||||
switch modaltype{
|
switch modaltype{
|
||||||
@ -31,11 +28,7 @@ class Modal: GKEntity{
|
|||||||
addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten",
|
addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten",
|
||||||
footer: "", anchorPoint: anchorPoint))
|
footer: "", anchorPoint: anchorPoint))
|
||||||
addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
|
addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
|
||||||
if currentDraggedBase == nil{
|
|
||||||
print("nil")
|
|
||||||
}
|
|
||||||
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene, collisionBase: collisionBase)
|
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene, collisionBase: collisionBase)
|
||||||
print("send units")
|
|
||||||
self.removeModalEntities(gameScene: gameScene)
|
self.removeModalEntities(gameScene: gameScene)
|
||||||
}))
|
}))
|
||||||
addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: {
|
addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: {
|
||||||
@ -62,36 +55,10 @@ class Modal: GKEntity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
|
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
|
||||||
print("sendUnits: sendunits \(GameScene.sendUnits)")
|
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
for base in currentDraggedBase!.adjacencyList {
|
||||||
print("sendUnits: in here")
|
|
||||||
//print(base.component(ofType: DefaultBaseComponent.self)?.spriteNode)
|
|
||||||
if base == collisionBase {
|
if base == collisionBase {
|
||||||
print("sendUnits: in here 1")
|
|
||||||
print("sendUnits: sendunits \(GameScene.sendUnits)")
|
|
||||||
EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!)
|
EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* if currentDraggedBase == nil{
|
|
||||||
print("nil")
|
|
||||||
}
|
|
||||||
print(touchLocation.x)
|
|
||||||
print(touchLocation.y)
|
|
||||||
print("sendUnits: sendunits \(GameScene.sendUnits)")
|
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
|
||||||
print("sendUnits: in here")
|
|
||||||
//print(base.component(ofType: DefaultBaseComponent.self)?.spriteNode)
|
|
||||||
if gameScene.atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
|
||||||
// if !(EntityManager.sharedInstance.getTeamByBase(base: currentDraggedBase!) == EntityManager.sharedInstance.getTeamByBase(base: base)){
|
|
||||||
print("sendUnits: in here 1")
|
|
||||||
print("sendUnits: sendunits \(GameScene.sendUnits)")
|
|
||||||
EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!)
|
|
||||||
// }
|
|
||||||
} else if gameScene.atPoint(touchLocation) == currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
|
||||||
print("sendUnits: in here 2")
|
|
||||||
print("sendUnits: sendunits \(GameScene.sendUnits)")
|
|
||||||
EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!)
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
print("touches ended")
|
|
||||||
guard let touch = touches.first else {
|
guard let touch = touches.first else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -39,7 +38,6 @@ class GameScene: SKScene{
|
|||||||
|
|
||||||
if isMoveTouch{
|
if isMoveTouch{
|
||||||
isMoveTouch = false
|
isMoveTouch = false
|
||||||
print("touches Ended: isMoveTouch false")
|
|
||||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
||||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
||||||
|
|
||||||
@ -96,15 +94,9 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addAttackDetails(touchLocation: CGPoint){
|
func addAttackDetails(touchLocation: CGPoint){
|
||||||
print("addAttackDetails")
|
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
for base in currentDraggedBase!.adjacencyList {
|
||||||
print("base attack for")
|
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||||
collisionBase = base
|
collisionBase = base
|
||||||
print(touchLocation.x)
|
|
||||||
print(touchLocation.y)
|
|
||||||
print("add Modal BaseAttack")
|
|
||||||
print("add AttackDetails: sendunits \(GameScene.sendUnits)")
|
|
||||||
// TODO: change interaction based on collision instead of touchlocation
|
// TODO: change interaction based on collision instead of touchlocation
|
||||||
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
|
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
|
||||||
base: currentDraggedBase!,
|
base: currentDraggedBase!,
|
||||||
@ -115,7 +107,6 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkSlider(){
|
func checkSlider(){
|
||||||
print("slider")
|
|
||||||
for e in EntityManager.sharedInstance.entities{
|
for e in EntityManager.sharedInstance.entities{
|
||||||
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
||||||
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
|
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
|
||||||
@ -125,17 +116,12 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
|
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
|
||||||
print("checkbases")
|
|
||||||
for base in bases {
|
for base in bases {
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch {
|
||||||
print("checkbases: touched base")
|
|
||||||
if !isMoveTouch {
|
|
||||||
currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position
|
currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position
|
||||||
currentDraggedBase = base
|
currentDraggedBase = base
|
||||||
print("checkbases: isMoveTouch false")
|
|
||||||
}
|
}
|
||||||
isMoveTouch = true
|
isMoveTouch = true
|
||||||
print("checkbases: isMoveTouch true")
|
|
||||||
moveFireAndBase(base: base, touchLocation: touchLocation)
|
moveFireAndBase(base: base, touchLocation: touchLocation)
|
||||||
showNearestBases(base: base)
|
showNearestBases(base: base)
|
||||||
}
|
}
|
||||||
@ -148,7 +134,6 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func showNearestBases(base: Base){
|
func showNearestBases(base: Base){
|
||||||
print("show nearest Bases")
|
|
||||||
for adjacencyBase in base.adjacencyList {
|
for adjacencyBase in base.adjacencyList {
|
||||||
let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||||
node?.run(SKAction.sequence([
|
node?.run(SKAction.sequence([
|
||||||
|
Loading…
Reference in New Issue
Block a user