Feuer ergreift neue Basis nur, wenn im Modal Einheiten senden gedrückt wurde und gesendete Einheiten kommen an
This commit is contained in:
parent
7bebcf69df
commit
a7e6cd9f10
@ -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)
|
||||
|
@ -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<UITouch>, 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<UITouch>, 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([
|
||||
|
Loading…
Reference in New Issue
Block a user