diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 7371bab..daf1999 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -24,7 +24,6 @@ 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */; }; 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */; }; 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */; }; - 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; }; 9E0E459724796262009817A6 /* GameCenterManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0E459624796262009817A6 /* GameCenterManager.swift */; }; 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; }; 9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; }; @@ -43,7 +42,6 @@ 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; }; 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; }; 9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */; }; - AB0B88F6247AD89200C8DF66 /* SkillComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */; }; AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* MapFactory.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; }; @@ -89,7 +87,6 @@ 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerMoveType.swift; sourceTree = ""; }; 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundCalculatorService.swift; sourceTree = ""; }; 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingeClickButtonNode.swift; sourceTree = ""; }; - 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = ""; }; 9E0E459624796262009817A6 /* GameCenterManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterManager.swift; sourceTree = ""; }; 9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = ""; }; 9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = ""; }; @@ -109,7 +106,6 @@ 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = ""; }; 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = ""; }; - AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillComponent.swift; sourceTree = ""; }; AB21D7D4246C748A00B09CBA /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = ""; }; @@ -199,7 +195,6 @@ 116060F4245C56EA004E5A36 /* Components */ = { isa = PBXGroup; children = ( - 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */, 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */, 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */, 9E174C85245DD91500209FF0 /* ButtonComponent.swift */, @@ -210,7 +205,6 @@ C064E9A7246C0EA50022B228 /* LabelNode.swift */, 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */, 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */, - AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */, C05BB9C3247D890C00411249 /* SliderComponent.swift */, 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */, @@ -397,7 +391,6 @@ 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */, 9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */, 9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */, - 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */, 3E6785422472CBEC007B9DE4 /* Way.swift in Sources */, 110360D9244B101A008610AF /* GameScene.swift in Sources */, C04783F024685995004961FB /* SettingsScene.swift in Sources */, @@ -415,7 +408,6 @@ 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */, 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */, - AB0B88F6247AD89200C8DF66 /* SkillComponent.swift in Sources */, C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */, 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */, 3E67854024728368007B9DE4 /* CElements.swift in Sources */, diff --git a/GoldWars/GoldWars/Components/PlayerInfoComponent.swift b/GoldWars/GoldWars/Components/PlayerInfoComponent.swift index 5db9c9e..6b57cda 100644 --- a/GoldWars/GoldWars/Components/PlayerInfoComponent.swift +++ b/GoldWars/GoldWars/Components/PlayerInfoComponent.swift @@ -10,48 +10,3 @@ import Foundation import GameplayKit import GameKit - -class PlayerInfoComponent: GKComponent { - - var entityManager = EntityManager.gameEMInstance - var hostLabel:SKLabelNode - var hostUnitsLabel:SKLabelNode - - var peerLabel:SKLabelNode - var peerUnitsLabel:SKLabelNode - var host: GKPlayer? - var peer: GKPlayer? - - init(size: CGSize) { - host = GameCenterManager.sharedInstance.hostingPlayer - peer = GameCenterManager.sharedInstance.peerPlayer - hostLabel = SKLabelNode(text: host?.displayName) - hostUnitsLabel = SKLabelNode(text: "500" ) - peerLabel = SKLabelNode(text: peer?.displayName) - peerUnitsLabel = SKLabelNode(text: "500") - super.init() - hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95) - hostLabel.horizontalAlignmentMode = .left - peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95) - peerLabel.horizontalAlignmentMode = .right - hostUnitsLabel.position = CGPoint(x: size.width * 0.05, y: size.height * 0.9) - peerUnitsLabel.position = CGPoint(x: size.width * 0.95, y: size.height * 0.9) - setColor(labelNodes: [hostLabel,hostUnitsLabel,peerLabel,peerUnitsLabel]) - } - - func update(){ - hostUnitsLabel.text = "\(entityManager.getUnitSum(by: host!))" - peerUnitsLabel.text = "\(entityManager.getUnitSum(by: peer!))" - } - - func setColor(labelNodes: [SKLabelNode]) -> Void { - for label in labelNodes { - label.fontColor = SKColor.black - } - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - -} diff --git a/GoldWars/GoldWars/Components/SkillComponent.swift b/GoldWars/GoldWars/Components/SkillComponent.swift index 27f85b5..001aa2a 100644 --- a/GoldWars/GoldWars/Components/SkillComponent.swift +++ b/GoldWars/GoldWars/Components/SkillComponent.swift @@ -21,51 +21,5 @@ class SkillComponent: GKComponent { required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - } -class AtkSkillComponent: SkillComponent { - - init() { - super.init(textureName: "yellow_circle", - text: "Atk", - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), - isEnabled: true, - onButtonPress: {EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasAttackBoost = true})}) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} - -class DefSkillComponent: SkillComponent { - - init() { - super.init(textureName: "yellow_circle", - text: "Def", - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.85, y: EntityManager.gameEMInstance.scene.size.height * 0.1), - isEnabled: true, - onButtonPress: {EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasDefenseBoost = true})}) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} - -class SpySkillComponent: SkillComponent { - - init() { - super.init(textureName: "yellow_circle", - text: "Spy", - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1), - isEnabled: true, - onButtonPress: { print("Not implemented") } - ) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 19aab8b..6bf1d5b 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -42,6 +42,17 @@ class EntityManager { isModal = true } + if let hudEnitity = entity as? HUD { + scene.addChild(hudEnitity.hostLabel) + scene.addChild(hudEnitity.hostUnitsLabel) + scene.addChild(hudEnitity.peerLabel) + scene.addChild(hudEnitity.peerUnitsLabel) + scene.addChild(hudEnitity.defSkill) + scene.addChild(hudEnitity.atkSkill) + scene.addChild(hudEnitity.spySkill) + isModal = true + } + if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) { scene.addChild(spriteNode.labelNode) scene.addChild(spriteNode.spriteNode) @@ -49,15 +60,6 @@ class EntityManager { if let fire = entity.component(ofType: TeamComponent.self)?.fire{ scene.addChild(fire) } - if let skillButtonNode = entity.component(ofType: AtkSkillComponent.self)?.skillButtonNode { - scene.addChild(skillButtonNode) - } - if let skillButtonNode = entity.component(ofType: DefSkillComponent.self)?.skillButtonNode { - scene.addChild(skillButtonNode) - } - if let skillButtonNode = entity.component(ofType: SpySkillComponent.self)?.skillButtonNode { - scene.addChild(skillButtonNode) - } if let timer = entity.component(ofType: TimerComponent.self) { scene.addChild(timer.labelNode) } @@ -82,12 +84,6 @@ class EntityManager { if let wayNode = entity.component(ofType: DefaultWayComponent.self)?.shapeNode { scene.addChild(wayNode) } - if let playerInfos = entity.component(ofType: PlayerInfoComponent.self) { - scene.addChild(playerInfos.hostLabel) - scene.addChild(playerInfos.hostUnitsLabel) - scene.addChild(playerInfos.peerLabel) - scene.addChild(playerInfos.peerUnitsLabel) - } } func remove(_ entity: GKEntity) { @@ -165,7 +161,7 @@ class EntityManager { } } - getHUD()?.component(ofType: PlayerInfoComponent.self)?.update() + getHUD()!.updateUnitSum() } @@ -243,8 +239,8 @@ class EntityManager { return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button } - func getHUD() -> GKEntity? { - return entities.filter{$0 is HUD}[0] + func getHUD() -> HUD? { + return entities.filter{$0 is HUD}[0] as? HUD } func getSnapshotModel() -> SnapshotModel { diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index cdf9590..3b71497 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -7,20 +7,73 @@ // import GameplayKit +import GameKit class HUD: GKEntity { + var entityManager = EntityManager.gameEMInstance + var hostLabel:SKLabelNode + var hostUnitsLabel:SKLabelNode + + var peerLabel:SKLabelNode + var peerUnitsLabel:SKLabelNode + var host: GKPlayer? + var peer: GKPlayer? + + var spySkill: SingeClickButtonNode + var defSkill: SingeClickButtonNode + var atkSkill: SingeClickButtonNode + init(size: CGSize) { - super.init() + host = GameCenterManager.sharedInstance.hostingPlayer + peer = GameCenterManager.sharedInstance.peerPlayer + hostLabel = SKLabelNode(text: host?.displayName) + hostUnitsLabel = SKLabelNode(text: "500" ) + peerLabel = SKLabelNode(text: peer?.displayName) + peerUnitsLabel = SKLabelNode(text: "500") - addComponent(DefSkillComponent()) - addComponent(AtkSkillComponent()) - addComponent(SpySkillComponent()) + spySkill = SingeClickButtonNode( + textureName: "yellow_circle", + text: "Spy", + isEnabled: true, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + onButtonPress: { print("Not implemented") } + ) + defSkill = SingeClickButtonNode( + textureName: "yellow_circle", + text: "Def", + isEnabled: true, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.85, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + onButtonPress: {EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasDefenseBoost = true})} + ) + atkSkill = SingeClickButtonNode( + textureName: "yellow_circle", + text: "Atk", + isEnabled: true, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + onButtonPress: {EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasAttackBoost = true})} + ) + super.init() + hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95) + hostLabel.horizontalAlignmentMode = .left + peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95) + peerLabel.horizontalAlignmentMode = .right + hostUnitsLabel.position = CGPoint(x: size.width * 0.05, y: size.height * 0.9) + peerUnitsLabel.position = CGPoint(x: size.width * 0.95, y: size.height * 0.9) + setColor(labelNodes: [hostLabel,hostUnitsLabel,peerLabel,peerUnitsLabel]) addComponent(TimerComponent(text: "", anchorPoint: CGPoint(x: size.width * 0.5, y: size.height * 0.9), duration: 30)) - - addComponent(PlayerInfoComponent(size: size)) - + } + + func updateUnitSum(){ + hostUnitsLabel.text = "\(entityManager.getUnitSum(by: host!))" + peerUnitsLabel.text = "\(entityManager.getUnitSum(by: peer!))" + } + + func setColor(labelNodes: [SKLabelNode]) -> Void { + for label in labelNodes { + label.fontColor = SKColor.black + } } required init?(coder: NSCoder) { diff --git a/GoldWars/GoldWars/Map/CElements.swift b/GoldWars/GoldWars/Map/CElements.swift index 22fc4dc..1e158be 100644 --- a/GoldWars/GoldWars/Map/CElements.swift +++ b/GoldWars/GoldWars/Map/CElements.swift @@ -529,16 +529,12 @@ class CElement7: CenterElementProtocol { } func connectInnerBases() { - self.leftBase.adjacencyList.append(self.rightBase) self.leftBase.adjacencyList.append(self.topBase) self.leftBase.adjacencyList.append(self.bottomBase) - self.rightBase.adjacencyList.append(self.leftBase) self.rightBase.adjacencyList.append(self.topBase) self.rightBase.adjacencyList.append(self.bottomBase) self.topBase.adjacencyList.append(self.leftBase) self.topBase.adjacencyList.append(self.rightBase) - self.topBase.adjacencyList.append(self.bottomBase) - self.bottomBase.adjacencyList.append(self.topBase) self.bottomBase.adjacencyList.append(self.rightBase) self.bottomBase.adjacencyList.append(self.leftBase) } @@ -1116,16 +1112,12 @@ class CElement15: CenterElementProtocol { } func connectInnerBases() { - self.leftBase.adjacencyList.append(self.rightBase) self.leftBase.adjacencyList.append(self.topBase) self.leftBase.adjacencyList.append(self.bottomBase) - self.rightBase.adjacencyList.append(self.leftBase) self.rightBase.adjacencyList.append(self.topBase) self.rightBase.adjacencyList.append(self.bottomBase) self.topBase.adjacencyList.append(self.leftBase) self.topBase.adjacencyList.append(self.rightBase) - self.topBase.adjacencyList.append(self.bottomBase) - self.bottomBase.adjacencyList.append(self.topBase) self.bottomBase.adjacencyList.append(self.rightBase) self.bottomBase.adjacencyList.append(self.leftBase) } @@ -1209,16 +1201,12 @@ class CElement16: CenterElementProtocol { } func connectInnerBases() { - self.leftBase.adjacencyList.append(self.rightBase) self.leftBase.adjacencyList.append(self.topBase) self.leftBase.adjacencyList.append(self.bottomBase) - self.rightBase.adjacencyList.append(self.leftBase) self.rightBase.adjacencyList.append(self.topBase) self.rightBase.adjacencyList.append(self.bottomBase) self.topBase.adjacencyList.append(self.leftBase) self.topBase.adjacencyList.append(self.rightBase) - self.topBase.adjacencyList.append(self.bottomBase) - self.bottomBase.adjacencyList.append(self.topBase) self.bottomBase.adjacencyList.append(self.rightBase) self.bottomBase.adjacencyList.append(self.leftBase) } @@ -1302,16 +1290,12 @@ class CElement17: CenterElementProtocol { } func connectInnerBases() { - self.leftBase.adjacencyList.append(self.rightBase) self.leftBase.adjacencyList.append(self.topBase) self.leftBase.adjacencyList.append(self.bottomBase) - self.rightBase.adjacencyList.append(self.leftBase) self.rightBase.adjacencyList.append(self.topBase) self.rightBase.adjacencyList.append(self.bottomBase) self.topBase.adjacencyList.append(self.leftBase) self.topBase.adjacencyList.append(self.rightBase) - self.topBase.adjacencyList.append(self.bottomBase) - self.bottomBase.adjacencyList.append(self.topBase) self.bottomBase.adjacencyList.append(self.rightBase) self.bottomBase.adjacencyList.append(self.leftBase) }