diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 2811867..9d43fbe 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -67,10 +67,6 @@ class EntityManager { scene.addChild(spinningLogoEntity.warsLetteringNode) } - if let rulesEntity = entity as? Rules { - scene.addChild(rulesEntity.image) - } - if let wayEntity = entity as? Way { scene.addChild(wayEntity.localWayComponent) } @@ -370,17 +366,4 @@ class EntityManager { func updateTime(time: String) { getHUD()?.roundTimerLabel.text = time } - - func removeRules(){ - entities.forEach({entity in - if let rules = entity as? Rules { - rules.image.removeFromParent() - - if let button = rules.component(ofType: ButtonComponent.self) { - button.buttonNode.removeFromParent() - } - self.remove(rules) - } - }) - } } diff --git a/GoldWars/GoldWars/RulesScene.swift b/GoldWars/GoldWars/RulesScene.swift index 440f16a..62adc35 100644 --- a/GoldWars/GoldWars/RulesScene.swift +++ b/GoldWars/GoldWars/RulesScene.swift @@ -11,83 +11,95 @@ import GameplayKit class RulesScene: SKScene { + var image: SKSpriteNode? + override func sceneDidLoad() { EntityManager.rulesEMInstance.setScene(scene: self) - EntityManager.rulesEMInstance.add(Button(name: "backToMenuScene", - textureName: "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.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( + Button(name: "backToMenuScene", + textureName: "questionmark", + text: "", + position: CGPoint(x: self.size.width - 50, y: self.size.height - 50), + onButtonPress: { + EntityManager.rulesEMInstance.entities.removeAll() + self.view?.presentScene( + MenuScene(size: self.size), + transition: SKTransition.flipVertical(withDuration: 0.5) + ) + } + ) + ) + + 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 + ) + ) + + image = SKSpriteNode(imageNamed: "RulesSpiel") + image!.size = CGSize(width: size.width * 0.8, height: size.height * 0.8) + image!.position = CGPoint(x: size.width * 0.6, y: size.height * 0.6 - 150) + image!.zPosition = 4 + + self.addChild(image!) + + 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: { self.image!.texture = SKTexture(imageNamed: "RulesSpiel") } + ) + ) + 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: { self.image!.texture = SKTexture(imageNamed: "RulesBasen") } + ) + ) + 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: { self.image!.texture = SKTexture(imageNamed: "RulesEinheiten") } + ) + ) + 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: { self.image!.texture = SKTexture(imageNamed: "RulesSpielende") } + ) + ) + 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: { self.image!.texture = SKTexture(imageNamed: "RulesBoost") } + ) + ) + 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: { self.image!.texture = SKTexture(imageNamed: "RulesErfolge") } + ) ) - 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.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.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.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.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.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.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.rulesEMInstance.entities.removeAll() - self.view?.presentScene(scene, transition: transition) } override func update(_ currentTime: TimeInterval) { @@ -96,20 +108,3 @@ class RulesScene: SKScene { } } } - -class Rules: GKEntity { - - var image: SKSpriteNode - - init(rulesScene: RulesScene, textureName: String) { - let texture = SKTexture(imageNamed: textureName) - image = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8)) - image.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150) - image.zPosition = 4 - super.init() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -}