import GameKit and add ownershipPlayer to component
This commit is contained in:
parent
23248876ba
commit
43dd2aa853
@ -8,32 +8,36 @@
|
|||||||
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
import GameKit
|
||||||
|
|
||||||
class Base: GKEntity {
|
class Base: GKEntity {
|
||||||
|
|
||||||
var unitCount: Int
|
var unitCount: Int
|
||||||
var adjacencyList: Array<Base>
|
var adjacencyList: Array<Base>
|
||||||
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.unitCount = 0
|
||||||
self.adjacencyList = [Base]()
|
self.adjacencyList = [Base]()
|
||||||
self.changeOwnerShip = false
|
self.changeOwnership = false
|
||||||
|
self.ownershipPlayer = player
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
||||||
if(team != nil){
|
if(team != nil && player != nil){
|
||||||
addComponent(TeamComponent(team: team!, position: position))
|
addComponent(TeamComponent(team: team!, player: player!, position: position))
|
||||||
self.unitCount = 500
|
self.unitCount = 500
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func attackBase(base: Base, units:Int) -> [GKEntity]{
|
func attackBase(base: Base, units:Int) -> [GKEntity]{
|
||||||
base.changeOwnerShip = true
|
base.changeOwnership = true
|
||||||
self.unitCount -= units
|
base.ownershipPlayer = self.ownershipPlayer
|
||||||
base.unitCount += units
|
self.unitCount -= units
|
||||||
return [self, base]
|
base.unitCount += units
|
||||||
}
|
return [self, base]
|
||||||
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
Loading…
Reference in New Issue
Block a user