clean Code

This commit is contained in:
Niko Jochim 2020-06-18 17:24:34 +02:00
parent e2c08b51a2
commit e76f86b126

View File

@ -130,12 +130,10 @@ class GameScene: SKScene{
func gameEnd(){ func gameEnd(){
gameEndEffects = true gameEndEffects = true
GameCenterManager.sharedInstance.gameEnded = false GameCenterManager.sharedInstance.gameEnded = false
let move = SKAction.move(to: CGPoint(x: self.size.width / 2, y: self.size.height / 2), duration: 1) let move = SKAction.move(to: CGPoint(x: self.size.width / 2, y: self.size.height / 2), duration: 1)
let removeParticle = SKAction.removeFromParent() let removeParticle = SKAction.removeFromParent()
let sequence = SKAction.sequence([move, removeParticle]) let sequence = SKAction.sequence([move, removeParticle])
var n = 0 var actionAdded = false
for nodeChild in children { for nodeChild in children {
if nodeChild.name == "peerLabel" || nodeChild.name == "hostLabel"{ if nodeChild.name == "peerLabel" || nodeChild.name == "hostLabel"{
continue continue
@ -146,18 +144,15 @@ class GameScene: SKScene{
} }
if nodeChild.name != "clouds"{ if nodeChild.name != "clouds"{
nodeChild.run(sequence,completion: { nodeChild.run(sequence,completion: {
if n < 1 { if !actionAdded {
let explosion = self.getFinalExplosion() let explosion = self.getFinalExplosion()
self.addChild(explosion) self.addChild(explosion)
let action = SKAction.afterDelay(2) { let action = SKAction.afterDelay(2) {
(self.childNode(withName: "hostLabel") as! SKLabelNode).horizontalAlignmentMode = .center (self.childNode(withName: "hostLabel") as! SKLabelNode).horizontalAlignmentMode = .center
(self.childNode(withName: "peerLabel") as! SKLabelNode).horizontalAlignmentMode = .center (self.childNode(withName: "peerLabel") as! SKLabelNode).horizontalAlignmentMode = .center
self.childNode(withName: "hostLabel")?.run(SKAction.move(to: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.3), duration: 1)) self.childNode(withName: "hostLabel")?.run(SKAction.move(to: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.3), duration: 1))
self.childNode(withName: "peerLabel")?.run(SKAction.move(to: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.3), duration: 1)) self.childNode(withName: "peerLabel")?.run(SKAction.move(to: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.3), duration: 1))
self.initGameEndIcons() self.initGameEndIcons()
let node = ButtonNode(textureName: "yellow_button05", text: "Menu", isEnabled: true, position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 300), onButtonPress: { let node = ButtonNode(textureName: "yellow_button05", text: "Menu", isEnabled: true, position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 300), onButtonPress: {
self.backToMenuAction() self.backToMenuAction()
}) })
@ -165,9 +160,8 @@ class GameScene: SKScene{
self.addChild(node) self.addChild(node)
} }
explosion.run(action) explosion.run(action)
n += 1 actionAdded = true
} }
}) })
} }
} }
@ -177,14 +171,11 @@ class GameScene: SKScene{
let iclonSize = CGSize(width: 400, height: 400) let iclonSize = CGSize(width: 400, height: 400)
let winnerIcon = SKSpriteNode(texture: SKTexture(imageNamed: "winner")); let winnerIcon = SKSpriteNode(texture: SKTexture(imageNamed: "winner"));
winnerIcon.size = iclonSize winnerIcon.size = iclonSize
let loserIcon = SKSpriteNode(texture: SKTexture(imageNamed: "BaseTexture")) let loserIcon = SKSpriteNode(texture: SKTexture(imageNamed: "BaseTexture"))
loserIcon.size = iclonSize loserIcon.size = iclonSize
let loserFire = SKEmitterNode(fileNamed: "LoserFire") let loserFire = SKEmitterNode(fileNamed: "LoserFire")
loserFire?.zPosition = loserIcon.zPosition - 1 loserFire?.zPosition = loserIcon.zPosition - 1
loserFire?.run(SKAction.scale(by: 4, duration: 8)) loserFire?.run(SKAction.scale(by: 4, duration: 8))
let iconPosition1 = CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.55) let iconPosition1 = CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.55)
let iconPosition2 = CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.55) let iconPosition2 = CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.55)
let coin = SpinningLogo3DNode() let coin = SpinningLogo3DNode()
@ -193,14 +184,12 @@ class GameScene: SKScene{
coin.position = iconPosition1 coin.position = iconPosition1
loserIcon.position = iconPosition2 loserIcon.position = iconPosition2
loserFire?.position = iconPosition2 loserFire?.position = iconPosition2
} else { } else {
winnerIcon.position = iconPosition2 winnerIcon.position = iconPosition2
coin.position = iconPosition2 coin.position = iconPosition2
loserIcon.position = iconPosition1 loserIcon.position = iconPosition1
loserFire?.position = iconPosition1 loserFire?.position = iconPosition1
} }
self.addChild(winnerIcon) self.addChild(winnerIcon)
self.addChild(coin) self.addChild(coin)
self.addChild(loserIcon) self.addChild(loserIcon)
@ -217,28 +206,6 @@ class GameScene: SKScene{
return explosion return explosion
} }
func goldWarsCoin() -> SK3DNode {
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
}()
let node = SK3DNode(viewportSize: CGSize(width: 250, height: 250))
node.scnScene = scnScene
return node
}
func backToMenuAction() { func backToMenuAction() {
GameCenterManager.sharedInstance.reset() GameCenterManager.sharedInstance.reset()
self.gameEndEffects = false self.gameEndEffects = false
@ -247,7 +214,6 @@ class GameScene: SKScene{
self.view?.presentScene(MenuScene(size: self.size)) self.view?.presentScene(MenuScene(size: self.size))
entityManager.entities.removeAll() entityManager.entities.removeAll()
self.removeFromParent() self.removeFromParent()
} }
func checkBases(bases: Set<Base>, touchLocation: CGPoint){ func checkBases(bases: Set<Base>, touchLocation: CGPoint){