diff --git a/GoldWars/GoldWars/Components/TeamComponent.swift b/GoldWars/GoldWars/Components/TeamComponent.swift index 379a1cc..c5efa70 100644 --- a/GoldWars/GoldWars/Components/TeamComponent.swift +++ b/GoldWars/GoldWars/Components/TeamComponent.swift @@ -8,6 +8,7 @@ import SpriteKit import GameplayKit +import GameKit class TeamComponent: GKComponent { let team: Team @@ -29,6 +30,7 @@ class TeamComponent: GKComponent { } self.team = team + self.player = player super.init() } diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 70fe75d..1e43e87 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -22,8 +22,8 @@ class Base: GKEntity { super.init() addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position)) - if(team != nil){ - addComponent(TeamComponent(team: team!, position: position)) + if(team != nil && player != nil){ + addComponent(TeamComponent(team: team!, position: position, player: player!)) self.unitCount = 500 } } diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 38ef9a1..5d798b2 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -8,6 +8,7 @@ import SpriteKit import GameplayKit +import GameKit class EntityManager { diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index 516efb0..954f795 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -9,6 +9,8 @@ import GameplayKit class Modal: GKEntity{ + + var unitCount:Int var unitCount:Int diff --git a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift index beff433..412be97 100644 --- a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift +++ b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift @@ -21,6 +21,7 @@ class TwoPlayerDefaultTestMap: MapProtocol { func load() { + // Create Bases let basePlayerOne = Base( position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2), @@ -46,6 +47,7 @@ class TwoPlayerDefaultTestMap: MapProtocol { let basePlayerTwo = Base( position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2), + player: (!MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0], team: .team2 ) diff --git a/GoldWars/GoldWars/MatchmakingHelper.swift b/GoldWars/GoldWars/MatchmakingHelper.swift index 48628ce..26ff022 100644 --- a/GoldWars/GoldWars/MatchmakingHelper.swift +++ b/GoldWars/GoldWars/MatchmakingHelper.swift @@ -33,7 +33,6 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe var viewController: UIViewController? var mpMatchStarted: Bool var isServer: Bool - var spieler1: GKPlayer? var nameSpieler1 = "" var menusc: MenuScene? let localPlayer: GKLocalPlayer = GKLocalPlayer.local @@ -154,13 +153,9 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe if player == GKLocalPlayer.local { self.isServer = true - self.spieler1 = player - self.nameSpieler1 = self.spieler1!.displayName - } else { self.isServer = false } - self.delegate?.matchStarted() self.menusc!.loadScene(scene: GameScene(size: self.menusc!.size)) }) diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index bb47730..8df4c6d 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -8,6 +8,7 @@ import SpriteKit import GameplayKit +import GameKit class GameScene: SKScene{ @@ -22,20 +23,20 @@ class GameScene: SKScene{ entityManager.add(Background(size: self.size)) initMap() } - + func initMap() { MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2) } - + override func touchesEnded(_ touches: Set, with event: UIEvent?) { guard let touch = touches.first else { return } - + let touchLocation = touch.location(in: self) - - if isMoveTouch{ - isMoveTouch = false + + if isMoveTouch{ + isMoveTouch = false currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos @@ -76,9 +77,9 @@ class GameScene: SKScene{ } } } - + } - + override func touchesMoved(_ touches: Set, with event: UIEvent?) { guard let touch = touches.first else { return @@ -96,7 +97,7 @@ class GameScene: SKScene{ body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten " } } - let bases = entityManager.getBasesByTeam(for: .team1) + let bases = entityManager.getBaseByPlayer(for: GKLocalPlayer.local) for base in bases { if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ @@ -105,7 +106,7 @@ class GameScene: SKScene{ currentDraggedBase = base } isMoveTouch = true - + base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation base.component(ofType: TeamComponent.self)?.fire.position = touchLocation for adjacencyBase in base.adjacencyList {