Add adjacency mapping
This commit is contained in:
parent
918979d750
commit
67a345e9bf
@ -18,6 +18,7 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
init(scene: SKScene, entityManager: EntityManager) {
|
||||
self.entityManager = entityManager;
|
||||
self.size = scene.size
|
||||
self.adjacencyList = Dictionary()
|
||||
}
|
||||
|
||||
func adjacent(base: Base) -> Array<Base> {
|
||||
@ -25,7 +26,8 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
}
|
||||
|
||||
func create() {
|
||||
// Player one (leftest base)
|
||||
|
||||
// Create Bases
|
||||
let basePlayerOne = Base(
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2),
|
||||
team: .team1
|
||||
@ -48,12 +50,36 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75))
|
||||
]
|
||||
|
||||
// Player two (rightest base)
|
||||
let basePlayerTwo = Base(
|
||||
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2),
|
||||
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2),
|
||||
team: .team2
|
||||
)
|
||||
|
||||
// Create adjacency Mapping
|
||||
adjacencyList.updateValue(column1, forKey: basePlayerOne)
|
||||
|
||||
column1.forEach({currBase in
|
||||
adjacencyList[currBase] = Array<Base>()
|
||||
adjacencyList[currBase]?.append(contentsOf: column2)
|
||||
adjacencyList[currBase]?.append(basePlayerOne)
|
||||
})
|
||||
|
||||
column2.forEach({currBase in
|
||||
adjacencyList[currBase] = Array<Base>()
|
||||
adjacencyList[currBase]?.append(contentsOf: column3)
|
||||
adjacencyList[currBase]?.append(contentsOf: column1)
|
||||
})
|
||||
|
||||
column3.forEach({currBase in
|
||||
adjacencyList[currBase] = Array<Base>()
|
||||
adjacencyList[currBase]?.append(basePlayerTwo)
|
||||
adjacencyList[currBase]?.append(contentsOf: column3)
|
||||
})
|
||||
|
||||
adjacencyList.updateValue(column3, forKey: basePlayerTwo)
|
||||
|
||||
|
||||
// Add Bases to GameScene
|
||||
entityManager.add(basePlayerOne)
|
||||
|
||||
column1.forEach({base in entityManager.add(base)})
|
||||
|
Loading…
Reference in New Issue
Block a user