Extract player bases, simplify layout definition

This commit is contained in:
Marcel Schwarz 2020-05-02 19:07:02 +02:00
parent ffc4c05a46
commit 5a7c29b3b8
2 changed files with 34 additions and 52 deletions

View File

@ -30,52 +30,41 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
} }
func createNodes() { func createNodes() {
for i in 0...7 { // Player one (leftest base)
let base: Base let basePlayerOne = Base(
var position = CGPoint(x: 0, y: 0) textureName: "Base",
switch i { team: .team1 ,
case 0...2: position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2)
let width = self.size.width * 0.25 )
entityManager.add(basePlayerOne)
if i == 0 {
position = CGPoint(x: width, y: self.size.height * 0.25) var genericBasePositions = Array<CGPoint>()
}
if i == 1 { // First column
position = CGPoint(x: width, y: self.size.height * 0.5) genericBasePositions.append(CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.25))
} genericBasePositions.append(CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.5))
if i == 2 { genericBasePositions.append(CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.75))
position = CGPoint(x: width, y: self.size.height * 0.75)
} // Second column
genericBasePositions.append(CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.333))
case 3...4: genericBasePositions.append(CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.666))
let width = self.size.width * 0.5
// Third column
if i == 3 { genericBasePositions.append(CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.25))
position = CGPoint(x: width, y: self.size.height * 0.333) genericBasePositions.append(CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.5))
} genericBasePositions.append(CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75))
if i == 4 {
position = CGPoint(x: width, y: self.size.height * 0.666) for pos in genericBasePositions {
} entityManager.add(Base(textureName: "Base", team: nil, position: pos))
case 5...7:
let width = self.size.width * 0.75
if i == 5 {
position = CGPoint(x: width, y: self.size.height * 0.25)
}
if i == 6 {
position = CGPoint(x: width, y: self.size.height * 0.5)
}
if i == 7 {
position = CGPoint(x: width, y: self.size.height * 0.75)
}
default:
break
}
base = Base(textureName: "Base", team: nil, position: position)
entityManager.add(base)
} }
// Player two (rightest base)
let basePlayerTwo = Base(
textureName: "Base",
team: .team2 ,
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2)
)
entityManager.add(basePlayerTwo)
} }
func createNeighbourMapping() { func createNeighbourMapping() {

View File

@ -16,13 +16,6 @@ class GameScene: SKScene{
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager = EntityManager(scene: self) entityManager = EntityManager(scene: self)
entityManager.add(Base(textureName: "Base",
team: .team1 ,
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2)))
entityManager.add(Base(textureName: "Base",
team: .team2 ,
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2)))
entityManager.add(HUD(size: self.size)) entityManager.add(HUD(size: self.size))
initMap() initMap()
createBackground() createBackground()