same functionality just cleaned up code

This commit is contained in:
Chauntalle Schüle 2020-06-20 01:23:19 +02:00
parent b945f1e236
commit 29adaf14a7
2 changed files with 80 additions and 107 deletions

View File

@ -68,7 +68,7 @@ class EntityManager {
} }
if let rulesEntity = entity as? Rules { if let rulesEntity = entity as? Rules {
scene.addChild(rulesEntity.node1) scene.addChild(rulesEntity.node)
} }
if let wayEntity = entity as? Way { if let wayEntity = entity as? Way {
@ -374,7 +374,7 @@ class EntityManager {
func removeRules(){ func removeRules(){
entities.forEach({entity in entities.forEach({entity in
if let rules = entity as? Rules { if let rules = entity as? Rules {
rules.node1.removeFromParent() rules.node.removeFromParent()
if let button = rules.component(ofType: ButtonComponent.self) { if let button = rules.component(ofType: ButtonComponent.self) {
button.buttonNode.removeFromParent() button.buttonNode.removeFromParent()

View File

@ -11,135 +11,108 @@ import GameplayKit
class RulesScene: SKScene { class RulesScene: SKScene {
var entityManager = EntityManager.rulesEMInstance
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager.setScene(scene: self) EntityManager.rulesEMInstance.setScene(scene: self)
entityManager.add(Button(name: "backToMenuScene", EntityManager.rulesEMInstance.add(Button(name: "backToMenuScene",
textureName: "yellow_questionmark", textureName: "yellow_questionmark",
text: "", text: "",
position: CGPoint(x: self.size.width - 50, y: self.size.height - 50), position: CGPoint(x: self.size.width - 50, y: self.size.height - 50),
onButtonPress: { onButtonPress: {
let scene = MenuScene(size: self.size) let scene = MenuScene(size: self.size)
self.loadScene(scene: scene) self.loadScene(scene: scene)
})) }))
entityManager.add(Label(fontnamed: "Courier-Bold", EntityManager.rulesEMInstance.add(Label(fontnamed: "Courier-Bold",
name: "rulesLabel", name: "rulesLabel",
text: "Regelwerk", text: "Regelwerk",
fontSize: 90, fontSize: 90,
fontColor: .black, fontColor: .black,
position: CGPoint(x: self.size.width * 0.5, y: self.size.height - 100), position: CGPoint(x: self.size.width * 0.5, y: self.size.height - 100),
horizontalAlignmentMode: .center, horizontalAlignmentMode: .center,
vertikalAligmentMode: .baseline, vertikalAligmentMode: .baseline,
isAnimationEnabled: true, isAnimationEnabled: true,
isAnimationInfinite: true) isAnimationInfinite: true)
) )
entityManager.add(Button(name: "Spiel", EntityManager.rulesEMInstance.add(Button(name: "Spiel",
textureName: "yellow_button13", textureName: "yellow_button13",
text: "Spiel", text: "Spiel",
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150), position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150),
onButtonPress: { onButtonPress: {
self.entityManager.removeRules() EntityManager.rulesEMInstance.removeRules()
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Spielbeschreibung)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel"))
})) }))
entityManager.add(Button(name: "Basen", EntityManager.rulesEMInstance.add(Button(name: "Basen",
textureName: "yellow_button13", textureName: "yellow_button13",
text: "Basen", text: "Basen",
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85), position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85),
onButtonPress: { onButtonPress: {
self.entityManager.removeRules() EntityManager.rulesEMInstance.removeRules()
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Basen)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBasen"))
})) }))
entityManager.add(Button(name: "Einheiten", EntityManager.rulesEMInstance.add(Button(name: "Einheiten",
textureName: "yellow_button13", textureName: "yellow_button13",
text: "Einheiten", text: "Einheiten",
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20), position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20),
onButtonPress: { onButtonPress: {
self.entityManager.removeRules() EntityManager.rulesEMInstance.removeRules()
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Einheiten)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesEinheiten"))
})) }))
entityManager.add(Button(name: "Spielende", EntityManager.rulesEMInstance.add(Button(name: "Spielende",
textureName: "yellow_button13", textureName: "yellow_button13",
text: "Spielende", text: "Spielende",
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45), position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45),
onButtonPress: { onButtonPress: {
self.entityManager.removeRules() EntityManager.rulesEMInstance.removeRules()
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Spielende)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpielende"))
})) }))
entityManager.add(Button(name: "Boost", EntityManager.rulesEMInstance.add(Button(name: "Boost",
textureName: "yellow_button13", textureName: "yellow_button13",
text: "Boost", text: "Boost",
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110), position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110),
onButtonPress: { onButtonPress: {
self.entityManager.removeRules() EntityManager.rulesEMInstance.removeRules()
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Boost)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBoost"))
})) }))
entityManager.add(Button(name: "Erfolge", EntityManager.rulesEMInstance.add(Button(name: "Erfolge",
textureName: "yellow_button13", textureName: "yellow_button13",
text: "Erfolge", text: "Erfolge",
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175), position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175),
onButtonPress: { onButtonPress: {
self.entityManager.removeRules() EntityManager.rulesEMInstance.removeRules()
self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Achievements)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesErfolge"))
})) }))
entityManager.add(Background(size: self.size)) EntityManager.rulesEMInstance.add(Background(size: self.size))
entityManager.add(Rules(rulesScene: self, rulesCategory: .Basen)) EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel"))
} }
func loadScene(scene: SKScene) { func loadScene(scene: SKScene) {
let transition = SKTransition.flipVertical(withDuration: 0.5) let transition = SKTransition.flipVertical(withDuration: 0.5)
entityManager.entities.removeAll() EntityManager.rulesEMInstance.entities.removeAll()
self.view?.presentScene(scene, transition: transition) self.view?.presentScene(scene, transition: transition)
} }
override func update(_ currentTime: TimeInterval) { override func update(_ currentTime: TimeInterval) {
if entityManager.entities.count != 0 { if EntityManager.rulesEMInstance.entities.count != 0 {
entityManager.getBackground()!.update(deltaTime: currentTime) EntityManager.rulesEMInstance.getBackground()!.update(deltaTime: currentTime)
} }
} }
} }
enum RulesCategory: String{
case Spielbeschreibung
case Basen
case Spielende
case Achievements
case Einheiten
case Boost
}
class Rules: GKEntity { class Rules: GKEntity {
var entityManager = EntityManager.menuEMInstance var node: SKSpriteNode
var node1: SKSpriteNode
init(rulesScene: RulesScene, rulesCategory: RulesCategory) { init(rulesScene: RulesScene, textureName: String) {
let texture: SKTexture let texture = SKTexture(imageNamed: textureName)
switch rulesCategory { node = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8))
case .Spielbeschreibung: node.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150)
texture = SKTexture(imageNamed:"RulesSpiel") node.zPosition = 4
case .Basen: super.init()
texture = SKTexture(imageNamed:"RulesBasen")
case .Spielende:
texture = SKTexture(imageNamed:"RulesSpielende")
case .Achievements:
texture = SKTexture(imageNamed:"RulesErfolge")
case .Einheiten:
texture = SKTexture(imageNamed:"RulesEinheiten")
case .Boost:
texture = SKTexture(imageNamed:"RulesBoost")
}
node1 = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8))
node1.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150)
node1.zPosition = 4
super.init()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {