From a7e6cd9f10dcb40e8d804f2db9646c22f9bf8e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Sat, 16 May 2020 18:09:41 +0200 Subject: [PATCH] =?UTF-8?q?Feuer=20ergreift=20neue=20Basis=20nur,=20wenn?= =?UTF-8?q?=20im=20Modal=20Einheiten=20senden=20gedru=CC=88ckt=20wurde=20u?= =?UTF-8?q?nd=20gesendete=20Einheiten=20kommen=20an?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldWars/GoldWars/Entities/Modal.swift | 18 ++++++- GoldWars/GoldWars/Scenes/GameScene.swift | 67 ++++++++++++++++++++---- 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index d7e7be9..9529120 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -11,8 +11,9 @@ import GameplayKit class Modal: GKEntity{ var unitCount:Int + //var currentDraggedBase: Base? - init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: SKScene) { + init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint) { unitCount = base.unitCount super.init() switch modaltype{ @@ -28,7 +29,22 @@ class Modal: GKEntity{ addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten", footer: "", anchorPoint: anchorPoint)) addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { + //on Button press: sollen einheiten verrechnet werden,bei einheiten größer 0 feuer, entities removed werden +// self.currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos + for base in currentDraggedBase!.adjacencyList { + print("in here") + if gameScene.atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { + print("in here 2") + if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){ + print("sendUnits \(Int(GameScene.sendUnits))") + entityManager.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!) + // print("in here 3") + // sendUnits = 0 + } + } + } self.removeModalEntities(entityManager: entityManager, gameScene: gameScene) + })) addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: { self.removeModalEntities(entityManager: entityManager, gameScene: gameScene) diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index dae1566..2f2fa08 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -16,6 +16,7 @@ class GameScene: SKScene{ var isMoveTouch = false var currentDraggedBasePos = CGPoint() var currentDraggedBase : Base? + static var sendUnits: CGFloat = 0 override func sceneDidLoad() { entityManager = EntityManager(scene: self) @@ -28,7 +29,11 @@ class GameScene: SKScene{ MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2) } + /* + Aufgerufen: wenn Prozess beendet: Basis auf eine andere gezogen + */ override func touchesEnded(_ touches: Set, with event: UIEvent?) { + print("touchesEnded") guard let touch = touches.first else { return } @@ -36,31 +41,57 @@ class GameScene: SKScene{ let touchLocation = touch.location(in: self) if isMoveTouch{ + /* + Aufgerufen: wenn Prozess beendet: Basis auf eine andere gezogen + sendet 0 Einheiten, weil noch nicht slider betätugt wurde + */ isMoveTouch = false - currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos + print("isMoveTouch false") + currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos //currentdraggedbase position gespeichert currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos + //currentDraggedBase bekommt Feuerposition?: wenn auskommentiert verliert nur die alte Position das Feuer, 2 Feuer sind dann auf der neusten Position for base in currentDraggedBase!.adjacencyList { + //basis wurde berührt if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { // TODO: change interaction based on collision instead of touchlocation - if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){ + entityManager.add(Modal(modaltype: .BaseAttack, base: currentDraggedBase!, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - entityManager: entityManager, gameScene: self)) - entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!) - }else { + entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation)) + /* print("if") + print("sendUnits \(Int(self.sendUnits))") + entityManager.update((currentDraggedBase?.attackBase(base: base, units: Int(self.sendUnits)))!)*/ + }else { entityManager.add(Modal(modaltype: .BaseAttack, base: currentDraggedBase!, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - entityManager: entityManager, gameScene: self)) + entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation)) + print("else") } } } } else { + print("else ismoveTouch is false") + /* + for base in currentDraggedBase!.adjacencyList { + print("in here") + if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { + print("in here 2") + // if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){ + print("sendUnits \(Int(self.sendUnits))") + entityManager.update((currentDraggedBase?.attackBase(base: base, units: Int(self.sendUnits)))!) + // print("in here 3") + self.sendUnits = 0 + // } + } + }*/ + //add Base Details + for entity in entityManager.entities { let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode @@ -75,7 +106,8 @@ class GameScene: SKScene{ entityManager.add(Modal(modaltype: .BaseDetails, base: entity as! Base, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - entityManager: entityManager, gameScene: self)) + entityManager: entityManager, gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation)) + print("Added Base Details") } } } @@ -83,7 +115,11 @@ class GameScene: SKScene{ } + /* + Dauernd aufgerufen beim Prozess: Eine Basis auf eine andere zu ziehen. + */ override func touchesMoved(_ touches: Set, with event: UIEvent?) { + print("touchesMoved") guard let touch = touches.first else { return } @@ -94,24 +130,33 @@ class GameScene: SKScene{ child.touchesMoved(touches, with: event) } } - + //checken des Modals/slider des Modals, anzeigen der ausgewählten Units for e in entityManager.entities{ if let body = e.component(ofType: ModalContentComponent.self)?.body{ - body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten " - } } - + GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) + print("slider unit \(GameScene.sendUnits)") + body.text = "Schicke \(GameScene.sendUnits) Einheiten " + } + } + // alle Basen eines Players let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local) for base in bases { + //wenn die Touchlocation die position der Basis trifft if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch { + print("neue currentdraggedbase + position") currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position currentDraggedBase = base } isMoveTouch = true + print("isMoveTouch true") + //Feuer & Basis müssen sich mitbewegen können base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation base.component(ofType: TeamComponent.self)?.fire.position = touchLocation + + // jede basis die in der Nähe ist soll vergrößert werden. for adjacencyBase in base.adjacencyList { let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode node?.run(SKAction.sequence([