Merge branch 'development'

Conflicts:
	GoldWars/GoldWars.xcodeproj/project.pbxproj
	GoldWars/GoldWars/Entities/EntityManager.swift
This commit is contained in:
82joni1bif 2020-05-07 20:19:40 +02:00
commit b602841f8d
23 changed files with 225 additions and 100 deletions

View File

@ -37,6 +37,8 @@
9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */; }; 9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */; };
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */; }; 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */; };
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; }; 9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; };
9EBFD7552462CF5A00E1E219 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */; };
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; };
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.swift */; }; AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.swift */; };
@ -91,6 +93,8 @@
9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseNode.swift; sourceTree = "<group>"; }; 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseNode.swift; sourceTree = "<group>"; };
9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalBackgroundComponent.swift; sourceTree = "<group>"; }; 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalBackgroundComponent.swift; sourceTree = "<group>"; };
9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalContentComponent.swift; sourceTree = "<group>"; }; 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalContentComponent.swift; sourceTree = "<group>"; };
9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
9EC7E48A2461FBF700396BCD /* SliderNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderNode.swift; sourceTree = "<group>"; };
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; }; 9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; }; 9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; }; 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
@ -185,6 +189,8 @@
9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */, 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */,
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */, 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */,
2086465B2461B66200817C23 /* TimerComponent.swift */, 2086465B2461B66200817C23 /* TimerComponent.swift */,
9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */,
9EC7E48A2461FBF700396BCD /* SliderNode.swift */,
); );
path = Components; path = Components;
sourceTree = "<group>"; sourceTree = "<group>";
@ -381,8 +387,10 @@
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */, AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */,
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */, AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */,
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */, AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
9EBFD7552462CF5A00E1E219 /* SliderComponent.swift in Sources */,
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */, 9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */,
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */,
9E174C84245DD8CE00209FF0 /* Button.swift in Sources */, 9E174C84245DD8CE00209FF0 /* Button.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */,
2086465C2461B66200817C23 /* TimerComponent.swift in Sources */, 2086465C2461B66200817C23 /* TimerComponent.swift in Sources */,

View File

@ -10,8 +10,8 @@ import GameplayKit
class AtkBoostSkillComponent: GKComponent{ class AtkBoostSkillComponent: GKComponent{
let shapeNode :SKShapeNode let shapeNode: SKShapeNode
let labelNode :SKLabelNode let labelNode: SKLabelNode
init(text: String, texture: SKTexture?, anchorPoint: CGPoint) { init(text: String, texture: SKTexture?, anchorPoint: CGPoint) {
self.labelNode = SKLabelNode(text: text) self.labelNode = SKLabelNode(text: text)
@ -24,7 +24,6 @@ class AtkBoostSkillComponent: GKComponent{
shapeNode.fillColor = SKColor.gray shapeNode.fillColor = SKColor.gray
} }
super.init() super.init()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -6,17 +6,13 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
class AttackActionComponent : GKComponent { class AttackActionComponent: GKComponent {
init(unitCount: Int, adjacencyList: Array<Base>, position: CGPoint) { init(unitCount: Int, adjacencyList: Array<Base>, position: CGPoint) {
super.init() super.init()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
@ -25,7 +21,7 @@ class AttackActionComponent : GKComponent {
func action() { func action() {
// Not implemented yet
} }
} }

View File

@ -6,7 +6,6 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
class BackgroundComponent: GKComponent{ class BackgroundComponent: GKComponent{
@ -21,7 +20,7 @@ class BackgroundComponent: GKComponent{
sky.name = "clouds" sky.name = "clouds"
sky.zPosition = -1 sky.zPosition = -1
sky.size = CGSize(width: size.width, height: size.height) sky.size = CGSize(width: size.width, height: size.height)
sky.position = CGPoint(x: CGFloat(i) * sky.size.width , y: (size.height / 2)) sky.position = CGPoint(x: CGFloat(i) * sky.size.width, y: (size.height / 2))
nodes.append(sky) nodes.append(sky)
} }
super.init() super.init()
@ -36,8 +35,6 @@ class BackgroundComponent: GKComponent{
} }
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }

View File

@ -6,23 +6,20 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import SpriteKit import SpriteKit
class BaseNode: SKSpriteNode{ class BaseNode: SKSpriteNode{
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// TODO: PopUp Einheiten + Close PopUp // TODO: PopUp Einheiten + Close PopUp
self.run( self.run(
SKAction.sequence( SKAction.sequence(
[ [
SKAction.resize(byWidth: 20, height: 20, duration: 0.5), SKAction.resize(byWidth: 20, height: 20, duration: 0.5),
SKAction.resize(byWidth: -20, height: -20, duration: 0.5) SKAction.resize(byWidth: -20, height: -20, duration: 0.5)
] ]
) )
) )
} }
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

View File

@ -6,14 +6,13 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
class ButtonComponent: GKComponent { class ButtonComponent: GKComponent {
var buttonNode : ButtonNode var buttonNode: ButtonNode
init(iconName: String, text: String, position: CGPoint, isEnabled:Bool , onButtonPress: @escaping () -> ()) { init(iconName: String, text: String, position: CGPoint, isEnabled:Bool, onButtonPress: @escaping () -> ()) {
buttonNode = ButtonNode(iconName: iconName, buttonNode = ButtonNode(iconName: iconName,
text: text, text: text,
isEnabled: isEnabled, isEnabled: isEnabled,

View File

@ -6,12 +6,11 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import SpriteKit import SpriteKit
class ButtonNode : SKSpriteNode { class ButtonNode: SKSpriteNode {
var isEnabled:Bool{ var isEnabled: Bool{
didSet{ didSet{
if isEnabled { if isEnabled {
self.alpha = 1 self.alpha = 1
@ -25,7 +24,7 @@ class ButtonNode : SKSpriteNode {
let onButtonPress: () -> () let onButtonPress: () -> ()
init(iconName: String, text: String,isEnabled:Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { init(iconName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) {
self.onButtonPress = onButtonPress self.onButtonPress = onButtonPress
self.isEnabled = isEnabled self.isEnabled = isEnabled
let texture = SKTexture(imageNamed: "yellow_button04") let texture = SKTexture(imageNamed: "yellow_button04")
@ -33,42 +32,39 @@ class ButtonNode : SKSpriteNode {
self.position = position self.position = position
let label = SKLabelNode(fontNamed: "Courier-Bold") let label = SKLabelNode(fontNamed: "Courier-Bold")
label.fontSize = 30 label.fontSize = 30
label.fontColor = SKColor.black label.fontColor = SKColor.black
label.zPosition = 1 label.zPosition = 1
label.verticalAlignmentMode = .center label.verticalAlignmentMode = .center
label.text = text label.text = text
label.name = "label" label.name = "label"
if !iconName.isEmpty { if iconName.isEmpty {
label.position = CGPoint(x: 0, y: 0)
} else {
label.position = CGPoint(x: size.width * 0.25, y: 0) label.position = CGPoint(x: size.width * 0.25, y: 0)
let icon = SKSpriteNode(imageNamed: iconName) let icon = SKSpriteNode(imageNamed: iconName)
icon.position = CGPoint(x: -size.width * 0.25, y: 0) icon.position = CGPoint(x: -size.width * 0.25, y: 0)
icon.zPosition = 1 icon.zPosition = 1
self.addChild(icon) self.addChild(icon)
} else {
label.position = CGPoint(x: 0, y: 0)
} }
self.addChild(label) self.addChild(label)
isUserInteractionEnabled = true isUserInteractionEnabled = true
} }
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if isEnabled { if isEnabled {
let action = SKAction.sequence( let action = SKAction.sequence(
[ [
SKAction.scale(by: (3/4), duration: 0.3), SKAction.scale(by: (3/4), duration: 0.3),
SKAction.scale(by: (4/3), duration: 0.3), SKAction.scale(by: (4/3), duration: 0.3),
]) ]
)
self.childNode(withName: "label")?.run(action) self.childNode(withName: "label")?.run(action)
self.run(action) self.run(action)
onButtonPress() onButtonPress()
} }
} }

View File

@ -10,8 +10,8 @@ import GameplayKit
class DefBoostSkillComponent: GKComponent{ class DefBoostSkillComponent: GKComponent{
let shapeNode :SKShapeNode let shapeNode: SKShapeNode
let labelNode :SKLabelNode let labelNode: SKLabelNode
init(text: String, texture: SKTexture?, anchorPoint: CGPoint) { init(text: String, texture: SKTexture?, anchorPoint: CGPoint) {
self.labelNode = SKLabelNode(text: text) self.labelNode = SKLabelNode(text: text)
@ -24,7 +24,6 @@ class DefBoostSkillComponent: GKComponent{
shapeNode.fillColor = SKColor.gray shapeNode.fillColor = SKColor.gray
} }
super.init() super.init()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -6,14 +6,13 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
import SpriteKit import SpriteKit
class DefaultBaseComponent: GKComponent { class DefaultBaseComponent: GKComponent {
var spriteNode: BaseNode var spriteNode: BaseNode
init(texture: SKTexture,position: CGPoint) { init(texture: SKTexture, position: CGPoint) {
spriteNode = BaseNode(texture: texture, size: CGSize(width: 80, height: 80)) spriteNode = BaseNode(texture: texture, size: CGSize(width: 80, height: 80))
spriteNode.position = position spriteNode.position = position
super.init() super.init()

View File

@ -6,12 +6,11 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
import SpriteKit import SpriteKit
class ModalBackgroundComponent: GKComponent { class ModalBackgroundComponent: GKComponent {
let spriteNode : SKSpriteNode let spriteNode: SKSpriteNode
init(anchorPoint: CGPoint) { init(anchorPoint: CGPoint) {
let texture = SKTexture(imageNamed:"ModalBackground") let texture = SKTexture(imageNamed:"ModalBackground")

View File

@ -6,7 +6,6 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
import SpriteKit import SpriteKit
@ -31,7 +30,7 @@ class ModalContentComponent: GKComponent{
self.body.fontSize = 40 self.body.fontSize = 40
self.footer = SKLabelNode(text: footer) self.footer = SKLabelNode(text: footer)
self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20) self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40)
self.footer.fontName = "HelveticaNeue-Bold" self.footer.fontName = "HelveticaNeue-Bold"
self.footer.fontSize = 40 self.footer.fontSize = 40
super.init() super.init()

View File

@ -0,0 +1,23 @@
//
// SliderComponent.swift
// GoldWars
//
// Created by Niko Jochim on 05.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import GameplayKit
class SliderComponent: GKComponent {
var sliderNode: SliderNode
init(width: CGFloat, position: CGPoint) {
sliderNode = SliderNode(width: width, position: position)
super.init()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -0,0 +1,66 @@
//
// SliderNode.swift
// GoldWars
//
// Created by Niko Jochim on 05.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import SpriteKit
class SliderNode :SKNode {
var sliderLine :SKShapeNode
var sliderKnob :SliderKnob
var width: CGFloat
var getValue: CGFloat{
get{
return ((sliderKnob.position.x.rounded() - sliderKnob.min) / width)
}
}
init(width: CGFloat, position: CGPoint) {
self.width = width
sliderLine = SKShapeNode(rectOf: CGSize(width: width, height: 8))
sliderLine.position = position
sliderLine.fillColor = SKColor.white
sliderKnob = SliderKnob(circleOfRadius: 20)
sliderKnob.min = position.x - width / 2
sliderKnob.max = position.x + width / 2
sliderKnob.fillColor = SKColor.red
sliderKnob.zPosition = sliderLine.zPosition + 1
sliderKnob.position = CGPoint(x: sliderLine.position.x, y: sliderLine.position.y + 1)
super.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class SliderKnob: SKShapeNode {
var min = CGFloat()
var max = CGFloat()
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchLocation = touch.location(in: self.scene!)
if self.position.x >= min - 1 && self.position.x <= max + 1{
self.position.x = touchLocation.x
}
if(self.position.x <= min){
self.position.x = min
}
if(self.position.x >= max){
self.position.x = max
}
}
}
}

View File

@ -10,8 +10,8 @@ import GameplayKit
class SpySkillComponent: GKComponent{ class SpySkillComponent: GKComponent{
let shapeNode :SKShapeNode let shapeNode: SKShapeNode
let labelNode :SKLabelNode let labelNode: SKLabelNode
init(text: String, texture: SKTexture?, anchorPoint: CGPoint) { init(text: String, texture: SKTexture?, anchorPoint: CGPoint) {
self.labelNode = SKLabelNode(text: text) self.labelNode = SKLabelNode(text: text)
@ -24,7 +24,6 @@ class SpySkillComponent: GKComponent{
shapeNode.fillColor = SKColor.gray shapeNode.fillColor = SKColor.gray
} }
super.init() super.init()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {

View File

@ -11,7 +11,7 @@ import GameplayKit
class TeamComponent: GKComponent { class TeamComponent: GKComponent {
let team: Team let team: Team
let fire:SKEmitterNode let fire: SKEmitterNode
init(team: Team, position: CGPoint) { init(team: Team, position: CGPoint) {
fire = SKEmitterNode(fileNamed: "Fire")! fire = SKEmitterNode(fileNamed: "Fire")!
@ -20,7 +20,8 @@ class TeamComponent: GKComponent {
fire.name = "fire" fire.name = "fire"
fire.particleColorSequence = nil fire.particleColorSequence = nil
fire.particleColorBlendFactor = 1.0 fire.particleColorBlendFactor = 1.0
switch team {
switch team {
case .team1: fire.particleColor = SKColor.red case .team1: fire.particleColor = SKColor.red
case .team2: fire.particleColor = SKColor.purple case .team2: fire.particleColor = SKColor.purple
case .team3: fire.particleColor = SKColor.green case .team3: fire.particleColor = SKColor.green

View File

@ -6,7 +6,6 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
class Background: GKEntity { class Background: GKEntity {
@ -16,7 +15,6 @@ class Background: GKEntity {
addComponent(BackgroundComponent(size: size)) addComponent(BackgroundComponent(size: size))
} }
override func update(deltaTime seconds: TimeInterval) { override func update(deltaTime seconds: TimeInterval) {
component(ofType: BackgroundComponent.self)?.update() component(ofType: BackgroundComponent.self)?.update()
} }
@ -24,7 +22,4 @@ class Background: GKEntity {
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
} }

View File

@ -9,24 +9,31 @@
import SpriteKit import SpriteKit
import GameplayKit import GameplayKit
class Base : GKEntity { class Base: GKEntity {
var unitCount: Int var unitCount: Int
var adjacencyList: Array<Base> var adjacencyList: Array<Base>
var changeOwnerShip: Bool
init(position: CGPoint, team: Team! = nil) { init(position: CGPoint, team: Team! = nil) {
self.unitCount = 0 self.unitCount = 0
self.adjacencyList = [Base]() self.adjacencyList = [Base]()
self.changeOwnerShip = false
super.init() super.init()
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position)) addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
if(team != nil){ if(team != nil){
addComponent(TeamComponent(team: team!, position: position)) addComponent(TeamComponent(team: team!, position: position))
self.unitCount = 100 self.unitCount = 500
} }
} }
func attackBase(base: Base, units:Int) -> [GKEntity]{
base.changeOwnerShip = true
self.unitCount -= units
base.unitCount += units
return [self, base]
}
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")

View File

@ -6,24 +6,20 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameKit import GameKit
class Button : GKEntity{ class Button: GKEntity{
let name : String
let name: String
var isEnabled = true var isEnabled = true
init(name: String, iconName: String, text: String, position: CGPoint, onButtonPress: @escaping () -> ()) { init(name: String, iconName: String, text: String, position: CGPoint, onButtonPress: @escaping () -> ()) {
self.name = name self.name = name
super.init() super.init()
self.addComponent(ButtonComponent(iconName: iconName, text: text,position: position, isEnabled: isEnabled, onButtonPress: onButtonPress)) self.addComponent(ButtonComponent(iconName: iconName, text: text, position: position, isEnabled: isEnabled, onButtonPress: onButtonPress))
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
} }

View File

@ -6,7 +6,6 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import SpriteKit import SpriteKit
import GameplayKit import GameplayKit
@ -14,7 +13,7 @@ class EntityManager {
var entities = Set<GKEntity>() var entities = Set<GKEntity>()
let scene: SKScene let scene: SKScene
var isModal:Bool var isModal: Bool
init(scene: SKScene) { init(scene: SKScene) {
self.scene = scene self.scene = scene
@ -61,9 +60,12 @@ class EntityManager {
scene.addChild(node) scene.addChild(node)
} }
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
scene.addChild(sliderNode.sliderKnob)
scene.addChild(sliderNode.sliderLine)
}
} }
func remove(_ entity: GKEntity) { func remove(_ entity: GKEntity) {
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode { if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
spriteNode.removeFromParent() spriteNode.removeFromParent()
@ -77,9 +79,26 @@ class EntityManager {
modal.body.removeFromParent() modal.body.removeFromParent()
modal.footer.removeFromParent() modal.footer.removeFromParent()
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
sliderNode.sliderKnob.removeFromParent()
sliderNode.sliderLine.removeFromParent()
}
entities.remove(entity) entities.remove(entity)
} }
func update(_ entities: [GKEntity]){
for entity in entities {
self.entities.update(with: entity)
let base = (entity as! Base)
if base.changeOwnerShip {
base.addComponent(TeamComponent(team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!))
base.changeOwnerShip = false
scene.addChild(base.component(ofType: TeamComponent.self)!.fire)
}
}
}
func getBaseByTeam(for team: Team) -> GKEntity? { func getBaseByTeam(for team: Team) -> GKEntity? {
for entity in entities { for entity in entities {
if let teamComponent = entity.component(ofType: TeamComponent.self), if let teamComponent = entity.component(ofType: TeamComponent.self),
@ -96,15 +115,28 @@ class EntityManager {
return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.team == team } as! Set<Base> return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.team == team } as! Set<Base>
} }
func getTeamByBase(base: Base) -> Team? {
for entity in entities {
if entity is Base && entity == base{
for component in entity.components{
if component is TeamComponent {
return entity.component(ofType: TeamComponent.self)!.team
}
}
}
}
return nil
}
func getBackground() -> GKEntity? { func getBackground() -> GKEntity? {
return entities.filter{$0 is Background}[0] return entities.filter{$0 is Background}[0]
} }
func getBaseNodeByTeam(for team: Team) -> SKSpriteNode?{ func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? {
return getBaseByTeam(for: team)?.component(ofType: DefaultBaseComponent.self)?.spriteNode return getBaseByTeam(for: team)?.component(ofType: DefaultBaseComponent.self)?.spriteNode
} }
func getButtonByName(buttonName:String) -> Button{ func getButtonByName(buttonName:String) -> Button {
return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button
} }

View File

@ -6,15 +6,15 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
import GameplayKit import GameplayKit
class Modal:GKEntity{ class Modal: GKEntity{
var unitCount:Int
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) { init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
unitCount = base.unitCount
super.init() super.init()
switch modaltype{ switch modaltype{
case .BaseDetails: case .BaseDetails:
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
@ -22,8 +22,13 @@ class Modal:GKEntity{
body: "Diese Basis enthält \(base.unitCount) Einheiten", body: "Diese Basis enthält \(base.unitCount) Einheiten",
footer: "", footer: "",
anchorPoint: anchorPoint)) anchorPoint: anchorPoint))
default: case .BaseAttack:
break addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 80)))
addComponent(ModalContentComponent(header: "Angriff",
body: "Schicke \(unitCount / 2) Einheiten",
footer: "",
anchorPoint: anchorPoint))
} }
} }

View File

@ -6,8 +6,6 @@
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation
enum ModalType: String{ enum ModalType: String{
case BaseDetails case BaseDetails
case BaseAttack case BaseAttack

Binary file not shown.

View File

@ -28,17 +28,37 @@ class GameScene: SKScene{
} }
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { guard let touch = touches.first else {
return return
} }
let touchLocation = touch.location(in: self) let touchLocation = touch.location(in: self)
if !isMoveTouch { if isMoveTouch{
isMoveTouch = false
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
for base in currentDraggedBase!.adjacencyList {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
// TODO: change interaction based on collision instead of touchlocation
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
entityManager.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!)
}else {
entityManager.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
}
}
}
}
else {
for entity in entityManager.entities { for entity in entityManager.entities {
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
if entityManager.isModal && entity.isMember(of: Modal.self) { if entityManager.isModal && entity.isMember(of: Modal.self) {
@ -48,7 +68,6 @@ class GameScene: SKScene{
child.alpha = 1 child.alpha = 1
} }
} }
} }
if atPoint(touchLocation) == spriteNode && !entityManager.isModal { if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
@ -58,7 +77,6 @@ class GameScene: SKScene{
if(child.name != "fire"){ if(child.name != "fire"){
child.alpha = 0.3 child.alpha = 0.3
} }
} }
entityManager.add(Modal(modaltype: .BaseDetails, entityManager.add(Modal(modaltype: .BaseDetails,
base: entity as! Base, base: entity as! Base,
@ -67,14 +85,6 @@ class GameScene: SKScene{
} }
} }
} }
else {
isMoveTouch = false
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
} }
@ -84,6 +94,17 @@ class GameScene: SKScene{
} }
let touchLocation = touch.location(in: self) let touchLocation = touch.location(in: self)
for child in children {
if atPoint(touchLocation) == child {
child.touchesMoved(touches, with: event)
}
}
for e in entityManager.entities{
if let body = e.component(ofType: ModalContentComponent.self)?.body{
body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten "
} }
let bases = entityManager.getBasesByTeam(for: .team1) let bases = entityManager.getBasesByTeam(for: .team1)
for base in bases { for base in bases {
@ -91,7 +112,6 @@ class GameScene: SKScene{
if !isMoveTouch { if !isMoveTouch {
currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position
currentDraggedBase = base currentDraggedBase = base
} }
isMoveTouch = true isMoveTouch = true
@ -106,11 +126,6 @@ class GameScene: SKScene{
} }
} }
} }
} }
override func update(_ currentTime: TimeInterval) { override func update(_ currentTime: TimeInterval) {