From 43dd2aa8531f14025eac09721c568b15e585ff28 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Fri, 15 May 2020 12:01:55 +0200 Subject: [PATCH] import GameKit and add ownershipPlayer to component --- GoldWars/GoldWars/Entities/Base.swift | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 70fe75d..5ee587e 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -8,32 +8,36 @@ import SpriteKit import GameplayKit +import GameKit class Base: GKEntity { var unitCount: Int var adjacencyList: Array - var changeOwnerShip: Bool + var changeOwnership: Bool + var ownershipPlayer: GKPlayer - init(position: CGPoint, team: Team! = nil) { + init(position: CGPoint, player: GKPlayer! = nil, team: Team! = nil) { self.unitCount = 0 self.adjacencyList = [Base]() - self.changeOwnerShip = false + self.changeOwnership = false + self.ownershipPlayer = player 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!, player: player!, position: position)) self.unitCount = 500 } } - func attackBase(base: Base, units:Int) -> [GKEntity]{ - base.changeOwnerShip = true - self.unitCount -= units - base.unitCount += units - return [self, base] - } + func attackBase(base: Base, units:Int) -> [GKEntity]{ + base.changeOwnership = true + base.ownershipPlayer = self.ownershipPlayer + self.unitCount -= units + base.unitCount += units + return [self, base] + } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented")