Make base spawn at touch
This commit is contained in:
parent
e82a7a90d2
commit
79dcc78f75
@ -18,6 +18,7 @@
|
|||||||
110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360F8244B101B008610AF /* GoldWarsUITests.swift */; };
|
110360F9244B101B008610AF /* GoldWarsUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360F8244B101B008610AF /* GoldWarsUITests.swift */; };
|
||||||
11036111244B3D6A008610AF /* MenuScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 11036110244B3D6A008610AF /* MenuScene.sks */; };
|
11036111244B3D6A008610AF /* MenuScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 11036110244B3D6A008610AF /* MenuScene.sks */; };
|
||||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; };
|
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 */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@ -55,6 +56,7 @@
|
|||||||
110360FA244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
110360FA244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
11036110244B3D6A008610AF /* MenuScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = MenuScene.sks; sourceTree = "<group>"; };
|
11036110244B3D6A008610AF /* MenuScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = MenuScene.sks; sourceTree = "<group>"; };
|
||||||
11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
|
11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = "<group>"; };
|
||||||
|
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -105,6 +107,7 @@
|
|||||||
110360D1244B101A008610AF /* GoldWars */ = {
|
110360D1244B101A008610AF /* GoldWars */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
ABA03D9E244BD53D00A66916 /* Base */,
|
||||||
11036114244B3E8A008610AF /* Menu */,
|
11036114244B3E8A008610AF /* Menu */,
|
||||||
1103610F244B3D48008610AF /* Game */,
|
1103610F244B3D48008610AF /* Game */,
|
||||||
110360D2244B101A008610AF /* AppDelegate.swift */,
|
110360D2244B101A008610AF /* AppDelegate.swift */,
|
||||||
@ -153,6 +156,14 @@
|
|||||||
path = Menu;
|
path = Menu;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
ABA03D9E244BD53D00A66916 /* Base */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
ABA03D9F244BD54F00A66916 /* Base.swift */,
|
||||||
|
);
|
||||||
|
path = Base;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
/* Begin PBXNativeTarget section */
|
||||||
@ -288,6 +299,7 @@
|
|||||||
files = (
|
files = (
|
||||||
110360D9244B101A008610AF /* GameScene.swift in Sources */,
|
110360D9244B101A008610AF /* GameScene.swift in Sources */,
|
||||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
||||||
|
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
|
||||||
110360DB244B101A008610AF /* GameViewController.swift in Sources */,
|
110360DB244B101A008610AF /* GameViewController.swift in Sources */,
|
||||||
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
|
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
30
GoldWars/GoldWars/Base/Base.swift
Normal file
30
GoldWars/GoldWars/Base/Base.swift
Normal file
@ -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),
|
||||||
|
]
|
||||||
|
}
|
@ -31,7 +31,7 @@ class GameScene: SKScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
|
spawnBase()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
@ -49,4 +49,10 @@ class GameScene: SKScene {
|
|||||||
override func update(_ currentTime: TimeInterval) {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user