Found Bug, base collision now always registered and bases with fire can still send units

This commit is contained in:
Chauntalle Schüle 2020-05-18 21:21:06 +02:00
parent 7350654122
commit a41c9f4b30
2 changed files with 55 additions and 9 deletions

View File

@ -12,7 +12,10 @@ class Modal: GKEntity{
var unitCount:Int
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint) {
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
if currentDraggedBase == nil{
print("nil")
}
unitCount = base.unitCount
super.init()
switch modaltype{
@ -28,7 +31,11 @@ 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: {
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene)
if currentDraggedBase == nil{
print("nil")
}
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene, collisionBase: collisionBase)
print("send units")
self.removeModalEntities(gameScene: gameScene)
}))
addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: {
@ -54,13 +61,37 @@ class Modal: GKEntity{
}
}
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene){
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
print("sendUnits: sendunits \(GameScene.sendUnits)")
for base in currentDraggedBase!.adjacencyList {
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")
//print(base.component(ofType: DefaultBaseComponent.self)?.spriteNode)
if base == collisionBase {
print("sendUnits: in here 1")
print("sendUnits: sendunits \(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)))!)
}
}*/
}
}

View File

@ -16,6 +16,7 @@ class GameScene: SKScene{
var currentDraggedBasePos = CGPoint()
var currentDraggedBase : Base?
static var sendUnits: CGFloat = 0
var collisionBase: Base?
override func sceneDidLoad() {
EntityManager.sharedInstance.setScene(scene: self)
@ -29,6 +30,7 @@ class GameScene: SKScene{
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
print("touches ended")
guard let touch = touches.first else {
return
}
@ -37,6 +39,7 @@ class GameScene: SKScene{
if isMoveTouch{
isMoveTouch = false
print("touches Ended: isMoveTouch false")
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
@ -87,24 +90,32 @@ class GameScene: SKScene{
EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails,
base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation))
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
}
}
}
func addAttackDetails(touchLocation: CGPoint){
print("addAttackDetails")
for base in currentDraggedBase!.adjacencyList {
print("base attack for")
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
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
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation))
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
}
}
}
func checkSlider(){
print("slider")
for e in EntityManager.sharedInstance.entities{
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)
@ -114,14 +125,17 @@ class GameScene: SKScene{
}
func checkBases(bases: Set<Base>, touchLocation: CGPoint){
print("checkbases")
for base in bases {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
print("checkbases: touched base")
if !isMoveTouch {
currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position
currentDraggedBase = base
print("checkbases: isMoveTouch false")
}
isMoveTouch = true
print("checkbases: isMoveTouch true")
moveFireAndBase(base: base, touchLocation: touchLocation)
showNearestBases(base: base)
}
@ -134,6 +148,7 @@ class GameScene: SKScene{
}
func showNearestBases(base: Base){
print("show nearest Bases")
for adjacencyBase in base.adjacencyList {
let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode
node?.run(SKAction.sequence([