Merge branch '6-controller-basis' into 'development'

Resolve "[Controller] Basis"

Closes #6

See merge request marcel.schwarz/software-projekt-2!7
This commit is contained in:
Marcel Schwarz 2020-04-19 13:08:51 +00:00
commit 63e0336413
16 changed files with 81 additions and 33 deletions

View File

@ -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 = "<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>"; };
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
};
ABA03D9E244BD53D00A66916 /* Base */ = {
isa = PBXGroup;
children = (
ABA03D9F244BD54F00A66916 /* Base.swift */,
);
path = Base;
sourceTree = "<group>";
};
/* 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 */,
);

View File

@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "Blue-small.png",
"filename" : "base-small.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Blue-medium.png",
"filename" : "base-medium.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Blue-large.png",
"filename" : "base-large.png",
"idiom" : "universal",
"scale" : "3x"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -1,6 +0,0 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"filename" : "Red-small.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Red-medium.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Red-large.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -0,0 +1,46 @@
//
// 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: BaseNode!
init(frame: CGRect, color: UIColor, position: CGPoint) {
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<UITouch>, 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)
]
)
)
}
}
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),
]
}

Binary file not shown.

View File

@ -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) {