From ee69f2c34587cfb36c1f420d0a99970e68987932 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 18 Apr 2020 16:50:57 +0200 Subject: [PATCH] Add Bases, Autospawn 15 Bases Add visual effect when base is touched --- GoldWars/GoldWars/Base/Base.swift | 20 ++++++++++++++++-- GoldWars/GoldWars/Game/GameScene.sks | Bin 4056 -> 4126 bytes GoldWars/GoldWars/Game/GameScene.swift | 27 ++++++++++++++++++------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/GoldWars/GoldWars/Base/Base.swift b/GoldWars/GoldWars/Base/Base.swift index 7df4d10..393c427 100644 --- a/GoldWars/GoldWars/Base/Base.swift +++ b/GoldWars/GoldWars/Base/Base.swift @@ -10,13 +10,29 @@ import SpriteKit import GameplayKit class Base { - var spriteNode: SKSpriteNode! + var spriteNode: BaseNode! init(frame: CGRect, color: UIColor, position: CGPoint) { - spriteNode = SKSpriteNode(texture: SKTexture(imageNamed: "Base"), color: color, size: CGSize(width: 30.0, height: 30.0)) + spriteNode = BaseNode(texture: SKTexture(imageNamed: "Base"), color: color, size: CGSize(width: 50.0, height: 50.0)) spriteNode.colorBlendFactor = 1 spriteNode.name = "Base" spriteNode.position = position + spriteNode.isUserInteractionEnabled = true + } +} + +class BaseNode: SKSpriteNode { + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + print("\(self.name!) was touched and is located at \(self.position)") + self.run( + SKAction.sequence( + [ + SKAction.resize(byWidth: 20, height: 20, duration: 0.5), + SKAction.resize(byWidth: -20, height: -20, duration: 0.5) + ] + ) + ) + } } diff --git a/GoldWars/GoldWars/Game/GameScene.sks b/GoldWars/GoldWars/Game/GameScene.sks index 693e11deb0f4e118617e2dd603eec366ae7f3704..ebf306afa8e8897c9ce187eaebeb9ac81f51cb73 100644 GIT binary patch delta 2169 zcmZ`(4OCTC7T){*oO{o`2Yn!^NCW~B%0DWBIg0QSl@V#E7#V|}@RY}|^Z1dU=pCJL zOjC1sR%)gQ)3P<=s6pv6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z7K$7ZU!&HhZPGSt z9ojZ+r`DzYTsx>8(vE5;wKLiW+Natz?JJ$?Ob^jV>S21g9;HX?F?yUnNuQ!m)${a6 zbidxKzpsCyU(x@mU)R4RNGKUW8c8#0Azso-e58%6BkRcq@;G^tJVmyUt;A1ukY~tF z@*^MFP4pAqLFFXjBF#vC@}2C zN~6+fFdB^}V~x>fv>Se7m+`#uve9Q8Gfo?4jq}Eb#zo_jImgU5zh^d^kC`22mwC{9 z%N#HV&8y}O8bZUUFODYD44O>~X$dW()wGt@(Pk=W8(l}&(+#wPZl!*@gFa37(4W%h zX)irO-=y!*3-oh(m3~35(Hqt>tJJbvRhG-DwrZ^=tJ!L?yw;=EdaK>qVm)i^wO+Jd zv3_H{YV}!XtxML&)*vG+k|nTIADhjxSq@voa#;71poj5 diff --git a/GoldWars/GoldWars/Game/GameScene.swift b/GoldWars/GoldWars/Game/GameScene.swift index 14839f9..df15181 100644 --- a/GoldWars/GoldWars/Game/GameScene.swift +++ b/GoldWars/GoldWars/Game/GameScene.swift @@ -13,9 +13,28 @@ class GameScene: SKScene { var entities = [GKEntity]() var graphs = [String : GKGraph]() + var bases = [Base]() override func sceneDidLoad() { + // Spawn bases + for _ in 1...15 { + let color = PlayerColors.colors.randomElement() + let xRange = Int(frame.minX + frame.width * 0.07)...Int(frame.maxX - frame.width * 0.07) + let yRange = Int(frame.minY + frame.height * 0.07)...Int(frame.maxY - frame.width * 0.07) + let position = CGPoint( + x: Int.random(in: xRange), + y: Int.random(in: yRange) + ) + + print("Generating Base at \(position)") + + let base = Base(frame: frame, color: color!, position: position) + + addChild(base.spriteNode) + bases.append(base) + } + } func touchDown(atPoint pos : CGPoint) { @@ -31,7 +50,7 @@ class GameScene: SKScene { } override func touchesBegan(_ touches: Set, with event: UIEvent?) { - spawnBase() + } override func touchesMoved(_ touches: Set, with event: UIEvent?) { @@ -49,10 +68,4 @@ class GameScene: SKScene { override func update(_ currentTime: TimeInterval) { } - - func spawnBase() { - let color = PlayerColors.colors.randomElement() - let base = Base(frame: frame, color: color!, position: CGPoint(x: 100, y: 100)) - addChild(base.spriteNode) - } }