From 5a7c29b3b88c6889d54cf5cf323e9c0a25499699 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 2 May 2020 19:07:02 +0200 Subject: [PATCH] Extract player bases, simplify layout definition --- .../Map/TwoPlayerDefaultTestMap.swift | 79 ++++++++----------- GoldWars/GoldWars/Scenes/GameScene.swift | 7 -- 2 files changed, 34 insertions(+), 52 deletions(-) diff --git a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift index c5e818a..ee4ab71 100644 --- a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift +++ b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift @@ -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 - - 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) - } - - 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 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) + + var genericBasePositions = Array() + + // 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)) } + + // 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() { diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 6096538..906d45b 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -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()