diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 14ad1f2..d04b888 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360F8244B101B008610AF /* GoldWarsUITests.swift */; }; 11036111244B3D6A008610AF /* MenuScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 11036110244B3D6A008610AF /* MenuScene.sks */; }; 11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; }; + ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -55,6 +56,7 @@ 110360FA244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 11036110244B3D6A008610AF /* MenuScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = MenuScene.sks; sourceTree = ""; }; 11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = ""; }; + ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -105,6 +107,7 @@ 110360D1244B101A008610AF /* GoldWars */ = { isa = PBXGroup; children = ( + ABA03D9E244BD53D00A66916 /* Base */, 11036114244B3E8A008610AF /* Menu */, 1103610F244B3D48008610AF /* Game */, 110360D2244B101A008610AF /* AppDelegate.swift */, @@ -153,6 +156,14 @@ path = Menu; sourceTree = ""; }; + ABA03D9E244BD53D00A66916 /* Base */ = { + isa = PBXGroup; + children = ( + ABA03D9F244BD54F00A66916 /* Base.swift */, + ); + path = Base; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -288,6 +299,7 @@ files = ( 110360D9244B101A008610AF /* GameScene.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */, + ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */, 110360D3244B101A008610AF /* AppDelegate.swift in Sources */, ); diff --git a/GoldWars/GoldWars/Base/Base.swift b/GoldWars/GoldWars/Base/Base.swift new file mode 100644 index 0000000..7df4d10 --- /dev/null +++ b/GoldWars/GoldWars/Base/Base.swift @@ -0,0 +1,30 @@ +// +// Base.swift +// GoldWars +// +// Created by Marcel Schwarz on 18.04.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import SpriteKit +import GameplayKit + +class Base { + var spriteNode: SKSpriteNode! + + init(frame: CGRect, color: UIColor, position: CGPoint) { + spriteNode = SKSpriteNode(texture: SKTexture(imageNamed: "Base"), color: color, size: CGSize(width: 30.0, height: 30.0)) + spriteNode.colorBlendFactor = 1 + spriteNode.name = "Base" + spriteNode.position = position + } +} + +enum PlayerColors { + static let colors = [ + UIColor(red: 231/255, green: 76/255, blue: 60/255, alpha: 1.0), + UIColor(red: 241/255, green: 196/255, blue: 15/255, alpha: 1.0), + UIColor(red: 46/255, green: 204/255, blue: 113/255, alpha: 1.0), + UIColor(red: 52/255, green: 152/255, blue: 219/255, alpha: 1.0), + ] +} diff --git a/GoldWars/GoldWars/Game/GameScene.swift b/GoldWars/GoldWars/Game/GameScene.swift index 413eb79..14839f9 100644 --- a/GoldWars/GoldWars/Game/GameScene.swift +++ b/GoldWars/GoldWars/Game/GameScene.swift @@ -31,7 +31,7 @@ class GameScene: SKScene { } override func touchesBegan(_ touches: Set, with event: UIEvent?) { - + spawnBase() } override func touchesMoved(_ touches: Set, with event: UIEvent?) { @@ -49,4 +49,10 @@ 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) + } }