Remove fireNode if base has no ownership. Move unitcount Label from BaseComponent to Teamcomponent and remove it if base has no ownership. Remove unused Team-Enum cases. Remove unused team-colors.
This commit is contained in:
parent
f50d00a416
commit
07e630881e
@ -12,20 +12,11 @@ import GameKit
|
|||||||
|
|
||||||
class DefaultBaseComponent: GKComponent {
|
class DefaultBaseComponent: GKComponent {
|
||||||
var spriteNode: BaseNode
|
var spriteNode: BaseNode
|
||||||
var labelNode : SKLabelNode
|
|
||||||
|
|
||||||
init(texture: SKTexture, position: CGPoint) {
|
init(texture: SKTexture, position: CGPoint) {
|
||||||
spriteNode = BaseNode(texture: texture, size: CGSize(width: 100, height: 100))
|
spriteNode = BaseNode(texture: texture, size: CGSize(width: 100, height: 100))
|
||||||
spriteNode.position = position
|
spriteNode.position = position
|
||||||
spriteNode.zPosition = 2
|
spriteNode.zPosition = 2
|
||||||
labelNode = SKLabelNode(text: "")
|
|
||||||
labelNode.fontColor = SKColor.black
|
|
||||||
labelNode.horizontalAlignmentMode = .left
|
|
||||||
labelNode.verticalAlignmentMode = .center
|
|
||||||
labelNode.fontName = "AvenirNext-Bold"
|
|
||||||
labelNode.fontSize = 15
|
|
||||||
labelNode.position = CGPoint(x: position.x + 30 , y: position.y - 50 )
|
|
||||||
labelNode.zPosition = spriteNode.zPosition - 1
|
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ class TeamComponent: GKComponent {
|
|||||||
var team: Team
|
var team: Team
|
||||||
var player: GKPlayer
|
var player: GKPlayer
|
||||||
let fire: SKEmitterNode
|
let fire: SKEmitterNode
|
||||||
|
var unitcountLabel : SKLabelNode
|
||||||
|
|
||||||
init(team: Team, player: GKPlayer, position: CGPoint) {
|
init(team: Team, player: GKPlayer, position: CGPoint) {
|
||||||
fire = SKEmitterNode(fileNamed: "Fire")!
|
fire = SKEmitterNode(fileNamed: "Fire")!
|
||||||
@ -25,6 +26,15 @@ class TeamComponent: GKComponent {
|
|||||||
|
|
||||||
self.team = team
|
self.team = team
|
||||||
self.player = player
|
self.player = player
|
||||||
|
|
||||||
|
unitcountLabel = SKLabelNode(text: "")
|
||||||
|
unitcountLabel.fontColor = SKColor.black
|
||||||
|
unitcountLabel.horizontalAlignmentMode = .left
|
||||||
|
unitcountLabel.verticalAlignmentMode = .center
|
||||||
|
unitcountLabel.fontName = "AvenirNext-Bold"
|
||||||
|
unitcountLabel.fontSize = 15
|
||||||
|
unitcountLabel.position = CGPoint(x: position.x + 30 , y: position.y - 50 )
|
||||||
|
unitcountLabel.zPosition = 3
|
||||||
super.init()
|
super.init()
|
||||||
fire.particleColor = getColor(by: team)
|
fire.particleColor = getColor(by: team)
|
||||||
}
|
}
|
||||||
@ -37,8 +47,6 @@ class TeamComponent: GKComponent {
|
|||||||
switch team {
|
switch team {
|
||||||
case .team1: return SKColor.red
|
case .team1: return SKColor.red
|
||||||
case .team2: return SKColor.purple
|
case .team2: return SKColor.purple
|
||||||
case .team3: return SKColor.green
|
|
||||||
case .team4: return SKColor.gray
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class Base: GKEntity{
|
|||||||
self.unitCount = 500
|
self.unitCount = 500
|
||||||
}
|
}
|
||||||
if ownershipPlayer == GKLocalPlayer.local {
|
if ownershipPlayer == GKLocalPlayer.local {
|
||||||
self.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(unitCount)"
|
self.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(unitCount)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,9 +48,9 @@ class Base: GKEntity{
|
|||||||
}
|
}
|
||||||
self.unitCount -= units
|
self.unitCount -= units
|
||||||
base.unitCount += units
|
base.unitCount += units
|
||||||
self.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(self.unitCount)"
|
self.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(self.unitCount)"
|
||||||
if base.ownershipPlayer == GKLocalPlayer.local {
|
if base.ownershipPlayer == GKLocalPlayer.local {
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"
|
||||||
}
|
}
|
||||||
base.ownershipPlayer = self.ownershipPlayer
|
base.ownershipPlayer = self.ownershipPlayer
|
||||||
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID,
|
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID,
|
||||||
|
@ -64,12 +64,14 @@ class EntityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {
|
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {
|
||||||
scene.addChild(spriteNode.labelNode)
|
|
||||||
scene.addChild(spriteNode.spriteNode)
|
scene.addChild(spriteNode.spriteNode)
|
||||||
}
|
}
|
||||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
|
||||||
scene.addChild(fire)
|
if let spriteNode = entity.component(ofType: TeamComponent.self) {
|
||||||
|
scene.addChild(spriteNode.unitcountLabel)
|
||||||
|
scene.addChild(spriteNode.fire)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
||||||
scene.addChild(buttonNode)
|
scene.addChild(buttonNode)
|
||||||
}
|
}
|
||||||
@ -119,8 +121,9 @@ class EntityManager {
|
|||||||
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
if let spriteNode = entity.component(ofType: TeamComponent.self) {
|
||||||
scene.addChild(fire)
|
scene.addChild(spriteNode.unitcountLabel)
|
||||||
|
scene.addChild(spriteNode.fire)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.capture.fifty.bases", increasePercentComplete: 2)
|
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.capture.fifty.bases", increasePercentComplete: 2)
|
||||||
@ -140,31 +143,20 @@ class EntityManager {
|
|||||||
if snapBase.ownership != nil {
|
if snapBase.ownership != nil {
|
||||||
getOwnerBySnapBase = GameCenterManager.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
|
getOwnerBySnapBase = GameCenterManager.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
|
||||||
} else {
|
} else {
|
||||||
entity.removeComponent(ofType: TeamComponent.self)
|
if( entity.component(ofType: TeamComponent.self) != nil ) {
|
||||||
|
runExplosion(base: base)
|
||||||
|
entity.component(ofType: TeamComponent.self)!.fire.removeFromParent()
|
||||||
|
entity.component(ofType: TeamComponent.self)!.unitcountLabel.removeFromParent()
|
||||||
|
entity.removeComponent(ofType: TeamComponent.self)
|
||||||
|
}
|
||||||
base.ownershipPlayer = nil
|
base.ownershipPlayer = nil
|
||||||
}
|
}
|
||||||
if getOwnerBySnapBase != nil {
|
if getOwnerBySnapBase != nil {
|
||||||
if base.ownershipPlayer != getOwnerBySnapBase {
|
if base.ownershipPlayer != getOwnerBySnapBase {
|
||||||
//TODO: Outsource following with a AnimationManager
|
//TODO: Outsource following with a AnimationManager
|
||||||
let explosion = SKEmitterNode(fileNamed: "Explosion")!
|
runExplosion(base: base)
|
||||||
scene.addChild(explosion)
|
|
||||||
explosion.zPosition = 2
|
|
||||||
explosion.position = base.position
|
|
||||||
explosion.name = "explosion"
|
|
||||||
explosion.particleColorSequence = nil
|
|
||||||
explosion.particleColorBlendFactor = 1.0
|
|
||||||
let wait = SKAction.wait(forDuration: 1)
|
|
||||||
let removeParticle = SKAction.removeFromParent()
|
|
||||||
let sequence = SKAction.sequence([wait, removeParticle])
|
|
||||||
explosion.run(sequence)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if getOwnerBySnapBase == GKLocalPlayer.local {
|
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
|
||||||
} else {
|
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = ""
|
|
||||||
}
|
|
||||||
base.ownershipPlayer = getOwnerBySnapBase
|
base.ownershipPlayer = getOwnerBySnapBase
|
||||||
if (entity.component(ofType: TeamComponent.self) != nil) {
|
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||||
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
||||||
@ -179,6 +171,12 @@ class EntityManager {
|
|||||||
scene.addChild(fire)
|
scene.addChild(fire)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if getOwnerBySnapBase == GKLocalPlayer.local {
|
||||||
|
base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"
|
||||||
|
} else {
|
||||||
|
base.component(ofType: TeamComponent.self)?.unitcountLabel.text = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,6 +184,20 @@ class EntityManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runExplosion(base: Base) {
|
||||||
|
let explosion = SKEmitterNode(fileNamed: "Explosion")!
|
||||||
|
scene.addChild(explosion)
|
||||||
|
explosion.zPosition = 2
|
||||||
|
explosion.position = base.position
|
||||||
|
explosion.name = "explosion"
|
||||||
|
explosion.particleColorSequence = nil
|
||||||
|
explosion.particleColorBlendFactor = 1.0
|
||||||
|
let wait = SKAction.wait(forDuration: 1)
|
||||||
|
let removeParticle = SKAction.removeFromParent()
|
||||||
|
let sequence = SKAction.sequence([wait, removeParticle])
|
||||||
|
explosion.run(sequence)
|
||||||
|
}
|
||||||
|
|
||||||
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{
|
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{
|
||||||
return snapshotModel.baseEntites.filter { $0.baseId == baseId }[0]
|
return snapshotModel.baseEntites.filter { $0.baseId == baseId }[0]
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class HUD: GKEntity {
|
|||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1),
|
position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
EntityManager.gameEMInstance.getOpponentBases(for: EntityManager.gameEMInstance.getTeam()).forEach({base in base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"})
|
EntityManager.gameEMInstance.getOpponentBases(for: EntityManager.gameEMInstance.getTeam()).forEach({base in base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"})
|
||||||
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100)
|
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100)
|
||||||
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.spy.ten", increasePercentComplete: 10)
|
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.spy.ten", increasePercentComplete: 10)
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
enum Team: Int {
|
enum Team: Int {
|
||||||
case team1 = 1
|
case team1 = 1
|
||||||
case team2 = 2
|
case team2 = 2
|
||||||
case team3 = 3
|
|
||||||
case team4 = 4
|
|
||||||
|
|
||||||
static let allValues = [team1, team2,team3,team4]
|
static let allValues = [team1, team2]
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ class GameScene: SKScene{
|
|||||||
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
func moveFireAndBase(base: Base, touchLocation: CGPoint){
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||||
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.position = CGPoint(x:touchLocation.x + 30, y: touchLocation.y - 50)
|
base.component(ofType: TeamComponent.self)?.unitcountLabel.position = CGPoint(x:touchLocation.x + 30, y: touchLocation.y - 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
func showNearestBases(base: Base){
|
func showNearestBases(base: Base){
|
||||||
|
Loading…
Reference in New Issue
Block a user