Merge branch '104-teamkomponente-loschen' into 'development'
Resolve "Teamkomponente löschen" Closes #104 See merge request marcel.schwarz/software-projekt-2!124
This commit is contained in:
commit
0d8a134445
@ -12,20 +12,11 @@ import GameKit
|
||||
|
||||
class DefaultBaseComponent: GKComponent {
|
||||
var spriteNode: BaseNode
|
||||
var labelNode : SKLabelNode
|
||||
|
||||
init(texture: SKTexture, position: CGPoint) {
|
||||
spriteNode = BaseNode(texture: texture, size: CGSize(width: 100, height: 100))
|
||||
spriteNode.position = position
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ class TeamComponent: GKComponent {
|
||||
var team: Team
|
||||
var player: GKPlayer
|
||||
let fire: SKEmitterNode
|
||||
var unitcountLabel : SKLabelNode
|
||||
|
||||
init(team: Team, player: GKPlayer, position: CGPoint) {
|
||||
fire = SKEmitterNode(fileNamed: "Fire")!
|
||||
@ -25,6 +26,15 @@ class TeamComponent: GKComponent {
|
||||
|
||||
self.team = team
|
||||
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()
|
||||
fire.particleColor = getColor(by: team)
|
||||
}
|
||||
@ -37,8 +47,6 @@ class TeamComponent: GKComponent {
|
||||
switch team {
|
||||
case .team1: return SKColor.red
|
||||
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
|
||||
}
|
||||
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
|
||||
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 {
|
||||
base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"
|
||||
base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"
|
||||
}
|
||||
base.ownershipPlayer = self.ownershipPlayer
|
||||
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID,
|
||||
|
@ -64,12 +64,14 @@ class EntityManager {
|
||||
}
|
||||
|
||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {
|
||||
scene.addChild(spriteNode.labelNode)
|
||||
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 {
|
||||
scene.addChild(buttonNode)
|
||||
}
|
||||
@ -119,8 +121,9 @@ class EntityManager {
|
||||
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||
)
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.capture.fifty.bases", increasePercentComplete: 2)
|
||||
@ -140,12 +143,49 @@ class EntityManager {
|
||||
if snapBase.ownership != nil {
|
||||
getOwnerBySnapBase = GameCenterManager.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
|
||||
} else {
|
||||
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
|
||||
}
|
||||
if getOwnerBySnapBase != nil {
|
||||
if base.ownershipPlayer != getOwnerBySnapBase {
|
||||
//TODO: Outsource following with a AnimationManager
|
||||
runExplosion(base: base)
|
||||
}
|
||||
|
||||
base.ownershipPlayer = getOwnerBySnapBase
|
||||
if entity.component(ofType: TeamComponent.self) != nil {
|
||||
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
||||
} else {
|
||||
entity.addComponent(TeamComponent(
|
||||
team: getTeamByPlayer(playerName: snapBase.ownership!),
|
||||
player: getOwnerBySnapBase!,
|
||||
position: (entity.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||
)
|
||||
)
|
||||
if let spriteNode = entity.component(ofType: TeamComponent.self) {
|
||||
scene.addChild(spriteNode.unitcountLabel)
|
||||
scene.addChild(spriteNode.fire)
|
||||
}
|
||||
}
|
||||
|
||||
if getOwnerBySnapBase == GKLocalPlayer.local {
|
||||
base.component(ofType: TeamComponent.self)?.unitcountLabel.text = "\(base.unitCount)"
|
||||
} else {
|
||||
base.component(ofType: TeamComponent.self)?.unitcountLabel.text = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getHUD()!.updateUnitSum()
|
||||
|
||||
}
|
||||
|
||||
func runExplosion(base: Base) {
|
||||
let explosion = SKEmitterNode(fileNamed: "Explosion")!
|
||||
scene.addChild(explosion)
|
||||
explosion.zPosition = 2
|
||||
@ -159,33 +199,6 @@ class EntityManager {
|
||||
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
|
||||
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
||||
} else {
|
||||
entity.addComponent(TeamComponent(
|
||||
team: getTeamByPlayer(playerName: snapBase.ownership!),
|
||||
player: getOwnerBySnapBase!,
|
||||
position: (entity.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||
)
|
||||
)
|
||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
||||
scene.addChild(fire)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getHUD()!.updateUnitSum()
|
||||
|
||||
}
|
||||
|
||||
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{
|
||||
return snapshotModel.baseEntites.filter { $0.baseId == baseId }[0]
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class HUD: GKEntity {
|
||||
isEnabled: true,
|
||||
position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1),
|
||||
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.spy.ten", increasePercentComplete: 10)
|
||||
}
|
||||
|
@ -9,8 +9,6 @@
|
||||
enum Team: Int {
|
||||
case team1 = 1
|
||||
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){
|
||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.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){
|
||||
|
Loading…
Reference in New Issue
Block a user