Merge remote-tracking branch 'origin/29-uberarbeitung-der-menuscene-button' into cleanup_scenes

This commit is contained in:
Niko 2020-05-02 22:31:12 +02:00
commit fcf49e656d
7 changed files with 227 additions and 173 deletions

View File

@ -37,8 +37,9 @@
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; }; 9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; };
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
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 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.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 */
@ -97,8 +98,9 @@
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; }; 9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; }; 9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
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 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.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 */
@ -264,7 +266,8 @@
AB1D759E245DD2EA00671525 /* Map */ = { AB1D759E245DD2EA00671525 /* Map */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
AB1D759A245DD18100671525 /* MapProtocoll.swift */, AB1D759A245DD18100671525 /* MapProtocol.swift */,
AB1D759F245DEC0500671525 /* MapFactory.swift */,
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */, AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
); );
path = Map; path = Map;
@ -419,7 +422,8 @@
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
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 /* MapProtocol.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 */,
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */, 9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */,

View File

@ -9,21 +9,27 @@
import SpriteKit import SpriteKit
import GameplayKit import GameplayKit
class Base : GKEntity{ class Base : GKEntity {
var unitCount:Int var unitCount: Int
var adjacencyList: Array<Base>
init(textureName:String, team: Team?,position: CGPoint ) {
self.unitCount = 0 init(position: CGPoint, team: Team! = nil) {
self.unitCount = 0
self.adjacencyList = [Base]()
super.init() super.init()
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: textureName), position: position))
if(team != nil){ addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
addComponent(TeamComponent(team: team!, position: position)) if(team != nil){
addComponent(TeamComponent(team: team!, position: position))
self.unitCount = 100 self.unitCount = 100
} }
} }
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
} required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
} }

View File

@ -0,0 +1,36 @@
//
// MapFactory.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
class MapFactory {
var twoPlayerMaps: [MapProtocol]!
var threePlayerMaps: [MapProtocol]!
var fourPlayerMaps: [MapProtocol]!
init(scene: SKScene, entityManager: EntityManager) {
self.twoPlayerMaps = [
TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager)
]
self.threePlayerMaps = [MapProtocol]()
self.fourPlayerMaps = [MapProtocol]()
}
func loadMap(playerCount: Int) {
if playerCount == 2 {
twoPlayerMaps.randomElement()?.load()
} else if playerCount == 3 {
threePlayerMaps.randomElement()?.load()
} else {
fourPlayerMaps.randomElement()?.load()
}
}
}

View File

@ -0,0 +1,20 @@
//
// MapProtocoll.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
protocol MapProtocol {
var size: CGSize! {get set}
var entityManager: EntityManager! {get set}
init(scene: SKScene, entityManager: EntityManager)
func load()
}

View File

@ -1,15 +0,0 @@
//
// MapProtocoll.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
protocol MapProtocoll {
func adjacent(base: Base) -> Array<Base>
}

View File

@ -7,13 +7,75 @@
// //
import Foundation import Foundation
import SpriteKit
class TwoPlayerDefaultTestMap: MapProtocoll { class TwoPlayerDefaultTestMap: MapProtocol {
func adjacent(base: Base) -> Array<Base> { var entityManager: EntityManager!
return Array() var size: CGSize!
required init(scene: SKScene, entityManager: EntityManager) {
self.entityManager = entityManager;
self.size = scene.size
} }
func load() {
// Create Bases
let basePlayerOne = Base(
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2),
team: .team1
)
let column1 = [
Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.25)),
Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.5)),
Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.75))
]
let column2 = [
Base(position: CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.333)),
Base(position: CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.666))
]
let column3 = [
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.25)),
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.5)),
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75))
]
let basePlayerTwo = Base(
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2),
team: .team2
)
// Create adjacency Mapping
basePlayerOne.adjacencyList.append(contentsOf: column1)
column1.forEach({currBase in
currBase.adjacencyList.append(contentsOf: column2)
currBase.adjacencyList.append(basePlayerOne)
})
column2.forEach({currBase in
currBase.adjacencyList.append(contentsOf: column3)
currBase.adjacencyList.append(contentsOf: column1)
})
column3.forEach({currBase in
currBase.adjacencyList.append(basePlayerTwo)
currBase.adjacencyList.append(contentsOf: column3)
})
basePlayerTwo.adjacencyList.append(contentsOf: column3)
// Register bases with the EntityManager
entityManager.add(basePlayerOne)
column1.forEach({base in entityManager.add(base)})
column2.forEach({base in entityManager.add(base)})
column3.forEach({base in entityManager.add(base)})
entityManager.add(basePlayerTwo)
}
} }

View File

@ -10,140 +10,81 @@ import SpriteKit
import GameplayKit import GameplayKit
class GameScene: SKScene{ class GameScene: SKScene{
var entityManager: EntityManager! var entityManager: EntityManager!
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager = EntityManager(scene: self) entityManager = EntityManager(scene: self)
entityManager.add(Base(textureName: "Base", entityManager.add(HUD(size: self.size))
team: .team1 , initMap()
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2))) createBackground()
entityManager.add(Base(textureName: "Base", }
team: .team2 ,
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2))) func createBackground() {
entityManager.add(HUD(size: self.size)) for i in 0...2 {
initMap() let sky = SKSpriteNode(imageNamed: "SkyBackground")
createBackground() sky.name = "clouds"
sky.zPosition = -1
} sky.size = CGSize(width: (self.scene?.size.width)!, height: (self.scene?.size.height)!)
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (self.frame.size.height / 2))
func createBackground() {
for i in 0...2 { self.addChild(sky)
let sky = SKSpriteNode(imageNamed: "SkyBackground") }
sky.name = "clouds" }
sky.zPosition = -1
sky.size = CGSize(width: (self.scene?.size.width)!, height: (self.scene?.size.height)!) func initMap() {
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (self.frame.size.height / 2)) MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
}
self.addChild(sky)
}
} override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
// TODO: Issue #24 create Map generation Service return
func initMap() { }
createVirginBases() let touchLocation = touch.location(in: self)
}
for entity in entityManager.entities {
func createVirginBases() {
for i in 0...7 { let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
let base:Base
var position = CGPoint(x: 0, y: 0) if entityManager.isModal && entity.isMember(of: Modal.self) {
switch i { entityManager.remove(entity)
case 0...2: for child in self.children {
let width = self.size.width * 0.25 if(child.name != "fire"){
child.alpha = 1
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 atPoint(touchLocation) == spriteNode && !entityManager.isModal {
if i == 2{ spriteNode?.touchesBegan(touches, with: event)
position = CGPoint(x: width, y: self.size.height * 0.75) if !entityManager.isModal {
} for child in self.children {
if(child.name != "fire"){
case 3...4: child.alpha = 0.3
let width = self.size.width * 0.5 }
if i == 3{ }
position = CGPoint(x: width, y: self.size.height * 0.333) entityManager.add(Modal(modaltype: .BaseDetails,
} base: entity as! Base,
if i == 4{ anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
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) override func update(_ currentTime: TimeInterval) {
} self.enumerateChildNodes(withName: "clouds", using: ({
if i == 6{ (node, error) in
position = CGPoint(x: width, y: self.size.height * 0.5) node.position.x -= 2
} if node.position.x < -(self.scene?.size.width)! {
if i == 7{ node.position.x += (self.scene?.size.width)! * 3
position = CGPoint(x: width, y: self.size.height * 0.75) }
} }))
}
default:
break
}
base = Base(textureName: "Base", team: nil, position: position)
entityManager.add(base)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {
return
}
let touchLocation = touch.location(in: self)
for entity in entityManager.entities {
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
if entityManager.isModal && entity.isMember(of: Modal.self) {
entityManager.remove(entity)
for child in self.children {
if(child.name != "fire"){
child.alpha = 1
}
}
}
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
spriteNode?.touchesBegan(touches, with: event)
if !entityManager.isModal {
for child in self.children {
if(child.name != "fire"){
child.alpha = 0.3
}
}
entityManager.add(Modal(modaltype: .BaseDetails,
base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
}
}
}
}
override func update(_ currentTime: TimeInterval) {
self.enumerateChildNodes(withName: "clouds", using: ({
(node, error) in
node.position.x -= 2
if node.position.x < -(self.scene?.size.width)! {
node.position.x += (self.scene?.size.width)! * 3
}
}))
}
} }