Found Bug, base collision now always registered and bases with fire can still send units
This commit is contained in:
parent
7350654122
commit
a41c9f4b30
@ -12,7 +12,10 @@ class Modal: GKEntity{
|
|||||||
|
|
||||||
var unitCount:Int
|
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
|
unitCount = base.unitCount
|
||||||
super.init()
|
super.init()
|
||||||
switch modaltype{
|
switch modaltype{
|
||||||
@ -28,7 +31,11 @@ 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: {
|
||||||
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)
|
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: {
|
||||||
@ -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 {
|
for base in currentDraggedBase!.adjacencyList {
|
||||||
if gameScene.atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
print("sendUnits: in here")
|
||||||
if !(EntityManager.sharedInstance.getTeamByBase(base: currentDraggedBase!) == EntityManager.sharedInstance.getTeamByBase(base: base)){
|
//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)))!)
|
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)))!)
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ class GameScene: SKScene{
|
|||||||
var currentDraggedBasePos = CGPoint()
|
var currentDraggedBasePos = CGPoint()
|
||||||
var currentDraggedBase : Base?
|
var currentDraggedBase : Base?
|
||||||
static var sendUnits: CGFloat = 0
|
static var sendUnits: CGFloat = 0
|
||||||
|
var collisionBase: Base?
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
EntityManager.sharedInstance.setScene(scene: self)
|
EntityManager.sharedInstance.setScene(scene: self)
|
||||||
@ -29,6 +30,7 @@ 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
|
||||||
}
|
}
|
||||||
@ -37,6 +39,7 @@ 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
|
||||||
|
|
||||||
@ -87,24 +90,32 @@ class GameScene: SKScene{
|
|||||||
EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails,
|
EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails,
|
||||||
base: entity as! Base,
|
base: entity as! Base,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
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){
|
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
|
||||||
|
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!,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
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(){
|
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)
|
||||||
@ -114,14 +125,17 @@ 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{
|
||||||
|
print("checkbases: touched base")
|
||||||
if !isMoveTouch {
|
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)
|
||||||
}
|
}
|
||||||
@ -134,6 +148,7 @@ 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