Create Map Factory, remove texture name from base constructor

This commit is contained in:
Marcel Schwarz 2020-05-02 20:07:40 +02:00
parent 5a7c29b3b8
commit c1bb6a47de
5 changed files with 43 additions and 16 deletions

View File

@ -37,6 +37,7 @@
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocoll.swift */; }; AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocoll.swift */; };
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.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 */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -95,6 +96,7 @@
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; }; 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
AB1D759A245DD18100671525 /* MapProtocoll.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocoll.swift; sourceTree = "<group>"; }; AB1D759A245DD18100671525 /* MapProtocoll.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocoll.swift; sourceTree = "<group>"; };
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; }; AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -259,6 +261,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
AB1D759A245DD18100671525 /* MapProtocoll.swift */, AB1D759A245DD18100671525 /* MapProtocoll.swift */,
AB1D759F245DEC0500671525 /* MapFactory.swift */,
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */, AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
); );
path = Map; path = Map;
@ -414,6 +417,7 @@
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */, 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */,
AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */, AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */,
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */,
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */, AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */,

View File

@ -12,10 +12,10 @@ import GameplayKit
class Base : GKEntity{ class Base : GKEntity{
var unitCount:Int var unitCount:Int
init(textureName:String, team: Team?,position: CGPoint ) { init(team: Team?, position: CGPoint ) {
self.unitCount = 0 self.unitCount = 0
super.init() super.init()
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: textureName), position: position)) addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
if(team != nil){ if(team != nil){
addComponent(TeamComponent(team: team!, position: position)) addComponent(TeamComponent(team: team!, position: position))
self.unitCount = 100 self.unitCount = 100

View File

@ -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() {
}
}

View File

@ -25,14 +25,8 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
} }
func create() { func create() {
createNodes()
createNeighbourMapping()
}
func createNodes() {
// Player one (leftest base) // Player one (leftest base)
let basePlayerOne = Base( let basePlayerOne = Base(
textureName: "Base",
team: .team1 , team: .team1 ,
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2) 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)) genericBasePositions.append(CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75))
for pos in genericBasePositions { for pos in genericBasePositions {
entityManager.add(Base(textureName: "Base", team: nil, position: pos)) entityManager.add(Base(team: nil, position: pos))
} }
// Player two (rightest base) // Player two (rightest base)
let basePlayerTwo = Base( let basePlayerTwo = Base(
textureName: "Base",
team: .team2 , team: .team2 ,
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)
) )
entityManager.add(basePlayerTwo) entityManager.add(basePlayerTwo)
} }
func createNeighbourMapping() {
}
} }

View File

@ -36,8 +36,7 @@ class GameScene: SKScene{
// TODO: Issue #24 create Map generation Service // TODO: Issue #24 create Map generation Service
func initMap() { func initMap() {
self.map = TwoPlayerDefaultTestMap(scene: self, entityManager: self.entityManager) self.map = MapFactory(scene: self, entityManager: self.entityManager).getTwoPlayerMap()
self.map.create()
} }