diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 37f6e37..dbb539f 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocoll.swift */; }; AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; }; + AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; /* End PBXBuildFile section */ @@ -95,6 +96,7 @@ 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; AB1D759A245DD18100671525 /* MapProtocoll.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocoll.swift; sourceTree = ""; }; AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = ""; }; + AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -259,6 +261,7 @@ isa = PBXGroup; children = ( AB1D759A245DD18100671525 /* MapProtocoll.swift */, + AB1D759F245DEC0500671525 /* MapFactory.swift */, AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */, ); path = Map; @@ -414,6 +417,7 @@ 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */, AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */, + AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */, AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */, diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 75415f5..db68ee4 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -12,10 +12,10 @@ import GameplayKit class Base : GKEntity{ var unitCount:Int - init(textureName:String, team: Team?,position: CGPoint ) { + init(team: Team?, position: CGPoint ) { self.unitCount = 0 super.init() - addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: textureName), position: position)) + addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position)) if(team != nil){ addComponent(TeamComponent(team: team!, position: position)) self.unitCount = 100 diff --git a/GoldWars/GoldWars/Map/MapFactory.swift b/GoldWars/GoldWars/Map/MapFactory.swift new file mode 100644 index 0000000..160f176 --- /dev/null +++ b/GoldWars/GoldWars/Map/MapFactory.swift @@ -0,0 +1,35 @@ +// +// MapFactory.swift +// GoldWars +// +// Created by Marcel Schwarz on 02.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import SpriteKit + +class MapFactory { + + var entityManager: EntityManager! + var scene: SKScene! + + init(scene: SKScene, entityManager: EntityManager) { + self.entityManager = entityManager + self.scene = scene + } + + func getTwoPlayerMap() -> MapProtocoll { + let map = TwoPlayerDefaultTestMap(scene: self.scene, entityManager: self.entityManager) + map.create() + return map + } + + func getThreePlayerMap() { + + } + + func getFourPlayerMap() { + + } +} diff --git a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift index ee4ab71..887f78a 100644 --- a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift +++ b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift @@ -25,14 +25,8 @@ class TwoPlayerDefaultTestMap: MapProtocoll { } func create() { - createNodes() - createNeighbourMapping() - } - - func createNodes() { // Player one (leftest base) let basePlayerOne = Base( - textureName: "Base", team: .team1 , position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2) ) @@ -55,19 +49,14 @@ class TwoPlayerDefaultTestMap: MapProtocoll { 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)) + entityManager.add(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 906d45b..7397205 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -36,8 +36,7 @@ class GameScene: SKScene{ // TODO: Issue #24 create Map generation Service func initMap() { - self.map = TwoPlayerDefaultTestMap(scene: self, entityManager: self.entityManager) - self.map.create() + self.map = MapFactory(scene: self, entityManager: self.entityManager).getTwoPlayerMap() }