Minor code cleanup
This commit is contained in:
parent
bf88e1af83
commit
3b417cbe0e
@ -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) {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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{
|
||||||
@ -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")
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,8 @@
|
|||||||
// 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?) {
|
||||||
@ -22,7 +20,6 @@ class BaseNode: SKSpriteNode{
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
// Copyright © 2020 SP2. All rights reserved.
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
|
||||||
class ButtonComponent: GKComponent {
|
class ButtonComponent: GKComponent {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
// Copyright © 2020 SP2. All rights reserved.
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
|
|
||||||
class ButtonNode: SKSpriteNode {
|
class ButtonNode: SKSpriteNode {
|
||||||
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -20,6 +20,7 @@ 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
|
||||||
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ 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>
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
// 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
|
||||||
|
|
||||||
@ -19,11 +19,7 @@ class Button : GKEntity{
|
|||||||
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -58,9 +57,8 @@ class EntityManager {
|
|||||||
scene.addChild(node)
|
scene.addChild(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
|
@ -6,12 +6,10 @@
|
|||||||
// Copyright © 2020 SP2. All rights reserved.
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
|
||||||
class Modal: GKEntity{
|
class Modal: GKEntity{
|
||||||
|
|
||||||
|
|
||||||
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
|
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -28,7 +28,6 @@ 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
|
||||||
}
|
}
|
||||||
@ -36,9 +35,7 @@ class GameScene: SKScene{
|
|||||||
let touchLocation = touch.location(in: self)
|
let touchLocation = touch.location(in: self)
|
||||||
|
|
||||||
if !isMoveTouch {
|
if !isMoveTouch {
|
||||||
|
|
||||||
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 +45,6 @@ class GameScene: SKScene{
|
|||||||
child.alpha = 1
|
child.alpha = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
||||||
@ -58,7 +54,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,
|
||||||
|
Loading…
Reference in New Issue
Block a user