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 693e11d..ebf306a 100644 Binary files a/GoldWars/GoldWars/Game/GameScene.sks and b/GoldWars/GoldWars/Game/GameScene.sks differ 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) - } }