From c15234c9748184caa3829503baae21b9b59403b7 Mon Sep 17 00:00:00 2001 From: Niko Jochim <82joni1bif@hft-stuttgart.de> Date: Fri, 15 May 2020 21:29:15 +0200 Subject: [PATCH] add SpinningLogo to EC-System and EM --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 10 ++++- .../Components/SpinningLogoComponent.swift | 45 +++++++++++++++++++ .../GoldWars/Entities/EntityManager.swift | 9 ++-- .../Entities/SpinningLogoEntity.swift | 22 +++++++++ GoldWars/GoldWars/Scenes/MenuScene.swift | 43 +++--------------- 5 files changed, 89 insertions(+), 40 deletions(-) create mode 100644 GoldWars/GoldWars/Components/SpinningLogoComponent.swift create mode 100644 GoldWars/GoldWars/Entities/SpinningLogoEntity.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 5f06d79..4cc854b 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ 9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; }; 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; + 9EEDE029246F15590096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE028246F15590096C735 /* SpinningLogoComponent.swift */; }; + 9EEDE02B246F22AA0096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02A246F22AA0096C735 /* SpinningLogoEntity.swift */; }; AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.swift */; }; AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; }; AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; }; @@ -76,7 +78,7 @@ 110360E9244B101B008610AF /* GoldWarsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GoldWarsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 110360ED244B101B008610AF /* GoldWarsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoldWarsTests.swift; sourceTree = ""; }; 110360EF244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = ""; }; + 11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = ""; usesTabs = 0; }; 116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = ""; }; 11738A3A24508F68004426F1 /* Unit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = ""; }; 2086465B2461B66200817C23 /* TimerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerComponent.swift; sourceTree = ""; }; @@ -104,6 +106,8 @@ 9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = ""; }; 9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = ""; }; 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; + 9EEDE028246F15590096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = ""; usesTabs = 0; }; + 9EEDE02A246F22AA0096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = ""; }; AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = ""; }; AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = ""; }; AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; @@ -209,6 +213,7 @@ 2086465B2461B66200817C23 /* TimerComponent.swift */, 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */, 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, + 9EEDE028246F15590096C735 /* SpinningLogoComponent.swift */, ); path = Components; sourceTree = ""; @@ -222,6 +227,7 @@ 9E78ACB9245CBDAF00526FF7 /* HUD.swift */, 9E174C83245DD8CE00209FF0 /* Button.swift */, 9E174C89245E1A0A00209FF0 /* Background.swift */, + 9EEDE02A246F22AA0096C735 /* SpinningLogoEntity.swift */, ); path = Entities; sourceTree = ""; @@ -398,10 +404,12 @@ 9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */, 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, 11738A3B24508F68004426F1 /* Unit.swift in Sources */, + 9EEDE02B246F22AA0096C735 /* SpinningLogoEntity.swift in Sources */, 9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */, AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, + 9EEDE029246F15590096C735 /* SpinningLogoComponent.swift in Sources */, 9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */, 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */, diff --git a/GoldWars/GoldWars/Components/SpinningLogoComponent.swift b/GoldWars/GoldWars/Components/SpinningLogoComponent.swift new file mode 100644 index 0000000..ab01672 --- /dev/null +++ b/GoldWars/GoldWars/Components/SpinningLogoComponent.swift @@ -0,0 +1,45 @@ +// +// SpinningLogoComponent.swift +// GoldWars +// +// Created by Niko Jochim on 15.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import GameKit + +class SpinningLogoComponent: GKComponent{ + + var node : SK3DNode + + init(position: CGPoint) { + + let scnScene: SCNScene = { + let scnScene = SCNScene() + let cylinder = SCNCylinder(radius: 250, height: 50) + let logoMaterial = SCNMaterial() + let colorMaterial = SCNMaterial() + logoMaterial.diffuse.contents = UIImage(named: "logo_no_background") + colorMaterial.diffuse.contents = UIColor(red: 0.852, green: 0.649, blue: 0.123, alpha: 1) + cylinder.materials = [colorMaterial,logoMaterial,logoMaterial] + let cylinderNode = SCNNode(geometry: cylinder) + cylinderNode.eulerAngles = SCNVector3(x: Float(CGFloat.pi / 2), y: 0, z: Float(CGFloat.pi / 2)) + let action = SCNAction.rotateBy(x: CGFloat(GLKMathDegreesToRadians(360)), y:0 , z: 0, duration: 8) + let forever = SCNAction.repeatForever(action) + cylinderNode.runAction(forever) + scnScene.rootNode.addChildNode(cylinderNode) + return scnScene + }() + + self.node = SK3DNode(viewportSize: CGSize(width: 250, height: 250)) + node.scnScene = scnScene + node.position = position + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 6afa00e..809b51b 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -68,6 +68,9 @@ class EntityManager { if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode { scene.addChild(labelNode) } + if let node = entity.component(ofType: SpinningLogoComponent.self)?.node{ + scene.addChild(node) + } } func remove(_ entity: GKEntity) { @@ -100,9 +103,9 @@ class EntityManager { if base.changeOwnership { base.addComponent(TeamComponent( - team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, - player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player, - position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)! + team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, + player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player, + position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)! ) ) base.changeOwnership = false diff --git a/GoldWars/GoldWars/Entities/SpinningLogoEntity.swift b/GoldWars/GoldWars/Entities/SpinningLogoEntity.swift new file mode 100644 index 0000000..0e84923 --- /dev/null +++ b/GoldWars/GoldWars/Entities/SpinningLogoEntity.swift @@ -0,0 +1,22 @@ +// +// SpinningLogoEntity.swift +// GoldWars +// +// Created by Niko Jochim on 15.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import GameplayKit + +class SpinningLogoEntity: GKEntity { + + init(position: CGPoint) { + super.init() + self.addComponent(SpinningLogoComponent(position: position)) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 77103d1..292e594 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -9,9 +9,9 @@ import SpriteKit import SceneKit class MenuScene: SKScene { - + var entityManager: EntityManager! - + override func sceneDidLoad() { entityManager = EntityManager(scene: self) let midX = self.size.width / 2 @@ -25,9 +25,9 @@ class MenuScene: SKScene { self.loadScene(scene: GameScene(size: self.size)) SoundManager.sharedInstance.stopMenuMusic() } else { - MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self) + MatchmakingHelper.sharedInstance.presentMatchmaker(scene: self) } - })) + })) entityManager.add(Button(name: "settingsButton", iconName: "", text: "Settings", @@ -36,47 +36,18 @@ class MenuScene: SKScene { self.loadScene(scene: SettingsScene(size: self.size)) })) entityManager.add(Background(size: self.size)) - - let scnScene: SCNScene = { - let scnScene = SCNScene() - let cylinder = SCNCylinder(radius: 250, height: 50) - - let material = SCNMaterial() - let material2 = SCNMaterial() - material.diffuse.contents = UIImage(named: "logo_no_background") - material2.diffuse.contents = UIImage(named: "logo_kante") - - cylinder.materials = [material2,material,material] - - - let cylinderNode = SCNNode(geometry: cylinder) - cylinderNode.eulerAngles = SCNVector3(x: Float(CGFloat.pi / 2), y: 0, z: Float(CGFloat.pi / 2)) - - - - let action = SCNAction.rotateBy(x: CGFloat(GLKMathDegreesToRadians(360)), y:0 , z: 0, duration: 8) - let forever = SCNAction.repeatForever(action) - cylinderNode.runAction(forever) - scnScene.rootNode.addChildNode(cylinderNode) - return scnScene - }() - - let node = SK3DNode(viewportSize: CGSize(width: 250, height: 250)) - node.scnScene = scnScene - node.position = CGPoint(x: midX, y: midY + 200) - - self.addChild(node) + entityManager.add(SpinningLogoEntity(position: CGPoint(x: midX, y: midY + 200))) if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true { SoundManager.sharedInstance.startMenuMusic() } } - + func loadScene(scene: SKScene) { let transition = SKTransition.flipVertical(withDuration: 0.5) self.view?.presentScene(scene, transition: transition) } - + override func update(_ currentTime: TimeInterval) { entityManager.getBackground()!.update(deltaTime: currentTime) entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated