diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 28e82d3..15930a0 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -68,7 +68,7 @@ class EntityManager { } if let rulesEntity = entity as? Rules { - scene.addChild(rulesEntity.node1) + scene.addChild(rulesEntity.node) } if let wayEntity = entity as? Way { @@ -374,7 +374,7 @@ class EntityManager { func removeRules(){ entities.forEach({entity in if let rules = entity as? Rules { - rules.node1.removeFromParent() + rules.node.removeFromParent() if let button = rules.component(ofType: ButtonComponent.self) { button.buttonNode.removeFromParent() diff --git a/GoldWars/GoldWars/RulesScene.swift b/GoldWars/GoldWars/RulesScene.swift index c79bbf4..86696e4 100644 --- a/GoldWars/GoldWars/RulesScene.swift +++ b/GoldWars/GoldWars/RulesScene.swift @@ -11,135 +11,108 @@ import GameplayKit class RulesScene: SKScene { - var entityManager = EntityManager.rulesEMInstance - override func sceneDidLoad() { - entityManager.setScene(scene: self) - entityManager.add(Button(name: "backToMenuScene", - textureName: "yellow_questionmark", - text: "", - position: CGPoint(x: self.size.width - 50, y: self.size.height - 50), - onButtonPress: { - let scene = MenuScene(size: self.size) - self.loadScene(scene: scene) + EntityManager.rulesEMInstance.setScene(scene: self) + EntityManager.rulesEMInstance.add(Button(name: "backToMenuScene", + textureName: "yellow_questionmark", + text: "", + position: CGPoint(x: self.size.width - 50, y: self.size.height - 50), + onButtonPress: { + let scene = MenuScene(size: self.size) + self.loadScene(scene: scene) })) - entityManager.add(Label(fontnamed: "Courier-Bold", - name: "rulesLabel", - text: "Regelwerk", - fontSize: 90, - fontColor: .black, - position: CGPoint(x: self.size.width * 0.5, y: self.size.height - 100), - horizontalAlignmentMode: .center, - vertikalAligmentMode: .baseline, - isAnimationEnabled: true, - isAnimationInfinite: true) + EntityManager.rulesEMInstance.add(Label(fontnamed: "Courier-Bold", + name: "rulesLabel", + text: "Regelwerk", + fontSize: 90, + fontColor: .black, + position: CGPoint(x: self.size.width * 0.5, y: self.size.height - 100), + horizontalAlignmentMode: .center, + vertikalAligmentMode: .baseline, + isAnimationEnabled: true, + isAnimationInfinite: true) ) - entityManager.add(Button(name: "Spiel", - textureName: "yellow_button13", - text: "Spiel", - position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150), - onButtonPress: { - self.entityManager.removeRules() - self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Spielbeschreibung)) - + EntityManager.rulesEMInstance.add(Button(name: "Spiel", + textureName: "yellow_button13", + text: "Spiel", + position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150), + onButtonPress: { + EntityManager.rulesEMInstance.removeRules() + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel")) + })) - entityManager.add(Button(name: "Basen", - textureName: "yellow_button13", - text: "Basen", - position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85), - onButtonPress: { - self.entityManager.removeRules() - self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Basen)) - + EntityManager.rulesEMInstance.add(Button(name: "Basen", + textureName: "yellow_button13", + text: "Basen", + position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85), + onButtonPress: { + EntityManager.rulesEMInstance.removeRules() + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBasen")) + })) - entityManager.add(Button(name: "Einheiten", - textureName: "yellow_button13", - text: "Einheiten", - position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20), - onButtonPress: { - self.entityManager.removeRules() - self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Einheiten)) - + EntityManager.rulesEMInstance.add(Button(name: "Einheiten", + textureName: "yellow_button13", + text: "Einheiten", + position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20), + onButtonPress: { + EntityManager.rulesEMInstance.removeRules() + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesEinheiten")) + })) - entityManager.add(Button(name: "Spielende", - textureName: "yellow_button13", - text: "Spielende", - position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45), - onButtonPress: { - self.entityManager.removeRules() - self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Spielende)) - + EntityManager.rulesEMInstance.add(Button(name: "Spielende", + textureName: "yellow_button13", + text: "Spielende", + position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45), + onButtonPress: { + EntityManager.rulesEMInstance.removeRules() + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpielende")) + })) - entityManager.add(Button(name: "Boost", - textureName: "yellow_button13", - text: "Boost", - position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110), - onButtonPress: { - self.entityManager.removeRules() - self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Boost)) - + EntityManager.rulesEMInstance.add(Button(name: "Boost", + textureName: "yellow_button13", + text: "Boost", + position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110), + onButtonPress: { + EntityManager.rulesEMInstance.removeRules() + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBoost")) + })) - entityManager.add(Button(name: "Erfolge", - textureName: "yellow_button13", - text: "Erfolge", - position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175), - onButtonPress: { - self.entityManager.removeRules() - self.entityManager.add(Rules(rulesScene: self, rulesCategory: .Achievements)) - + EntityManager.rulesEMInstance.add(Button(name: "Erfolge", + textureName: "yellow_button13", + text: "Erfolge", + position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175), + onButtonPress: { + EntityManager.rulesEMInstance.removeRules() + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesErfolge")) + })) - entityManager.add(Background(size: self.size)) - entityManager.add(Rules(rulesScene: self, rulesCategory: .Basen)) + EntityManager.rulesEMInstance.add(Background(size: self.size)) + EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel")) } func loadScene(scene: SKScene) { let transition = SKTransition.flipVertical(withDuration: 0.5) - entityManager.entities.removeAll() + EntityManager.rulesEMInstance.entities.removeAll() self.view?.presentScene(scene, transition: transition) } override func update(_ currentTime: TimeInterval) { - if entityManager.entities.count != 0 { - entityManager.getBackground()!.update(deltaTime: currentTime) + if EntityManager.rulesEMInstance.entities.count != 0 { + EntityManager.rulesEMInstance.getBackground()!.update(deltaTime: currentTime) } } } - -enum RulesCategory: String{ - case Spielbeschreibung - case Basen - case Spielende - case Achievements - case Einheiten - case Boost -} - class Rules: GKEntity { - var entityManager = EntityManager.menuEMInstance - var node1: SKSpriteNode + var node: SKSpriteNode - init(rulesScene: RulesScene, rulesCategory: RulesCategory) { - let texture: SKTexture - switch rulesCategory { - case .Spielbeschreibung: - texture = SKTexture(imageNamed:"RulesSpiel") - case .Basen: - 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() + init(rulesScene: RulesScene, textureName: String) { + let texture = SKTexture(imageNamed: textureName) + node = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8)) + node.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150) + node.zPosition = 4 + super.init() } required init?(coder: NSCoder) {