Extract player bases, simplify layout definition
This commit is contained in:
parent
ffc4c05a46
commit
5a7c29b3b8
@ -30,52 +30,41 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
}
|
||||
|
||||
func createNodes() {
|
||||
for i in 0...7 {
|
||||
let base: Base
|
||||
var position = CGPoint(x: 0, y: 0)
|
||||
switch i {
|
||||
case 0...2:
|
||||
let width = self.size.width * 0.25
|
||||
// Player one (leftest base)
|
||||
let basePlayerOne = Base(
|
||||
textureName: "Base",
|
||||
team: .team1 ,
|
||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2)
|
||||
)
|
||||
entityManager.add(basePlayerOne)
|
||||
|
||||
if i == 0 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.25)
|
||||
}
|
||||
if i == 1 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.5)
|
||||
}
|
||||
if i == 2 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.75)
|
||||
var genericBasePositions = Array<CGPoint>()
|
||||
|
||||
// First column
|
||||
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))
|
||||
genericBasePositions.append(CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.75))
|
||||
|
||||
// Second column
|
||||
genericBasePositions.append(CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.333))
|
||||
genericBasePositions.append(CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.666))
|
||||
|
||||
// Third column
|
||||
genericBasePositions.append(CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.25))
|
||||
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))
|
||||
|
||||
for pos in genericBasePositions {
|
||||
entityManager.add(Base(textureName: "Base", team: nil, position: pos))
|
||||
}
|
||||
|
||||
case 3...4:
|
||||
let width = self.size.width * 0.5
|
||||
|
||||
if i == 3 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.333)
|
||||
}
|
||||
if i == 4 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.666)
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -16,13 +16,6 @@ class GameScene: SKScene{
|
||||
|
||||
override func sceneDidLoad() {
|
||||
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))
|
||||
initMap()
|
||||
createBackground()
|
||||
|
Loading…
Reference in New Issue
Block a user