diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 7d6a026..cd744fc 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; }; 3F79FFE02486F7CD003F79C3 /* Explosion.sks in Resources */ = {isa = PBXBuildFile; fileRef = 3F79FFDF2486F7CD003F79C3 /* Explosion.sks */; }; 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */; }; + 8B9CA5F1249A3C2E00561704 /* SkillButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B9CA5F0249A3C2E00561704 /* SkillButtonNode.swift */; }; 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */; }; 9E0E459724796262009817A6 /* GameCenterManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0E459624796262009817A6 /* GameCenterManager.swift */; }; 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; }; @@ -92,6 +93,7 @@ 3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = ""; }; 3F79FFDF2486F7CD003F79C3 /* Explosion.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Explosion.sks; sourceTree = ""; }; 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundCalculatorService.swift; sourceTree = ""; }; + 8B9CA5F0249A3C2E00561704 /* SkillButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillButtonNode.swift; sourceTree = ""; }; 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingeClickButtonNode.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 = ""; }; @@ -217,6 +219,7 @@ C064E9A7246C0EA50022B228 /* LabelNode.swift */, 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */, 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */, + 8B9CA5F0249A3C2E00561704 /* SkillButtonNode.swift */, C05BB9C3247D890C00411249 /* SliderComponent.swift */, 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */, @@ -427,6 +430,7 @@ 9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */, 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */, C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */, + 8B9CA5F1249A3C2E00561704 /* SkillButtonNode.swift in Sources */, 3EAD889524801B6A0048A10A /* RoundTimer.swift in Sources */, 3E67854024728368007B9DE4 /* CElements.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, diff --git a/GoldWars/GoldWars/Assets.xcassets/atk_button.imageset/Contents.json b/GoldWars/GoldWars/Assets.xcassets/atk_button.imageset/Contents.json new file mode 100644 index 0000000..fc47f62 --- /dev/null +++ b/GoldWars/GoldWars/Assets.xcassets/atk_button.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "atk_button.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/GoldWars/GoldWars/Assets.xcassets/atk_button.imageset/atk_button.png b/GoldWars/GoldWars/Assets.xcassets/atk_button.imageset/atk_button.png new file mode 100644 index 0000000..7b685da Binary files /dev/null and b/GoldWars/GoldWars/Assets.xcassets/atk_button.imageset/atk_button.png differ diff --git a/GoldWars/GoldWars/Assets.xcassets/def_button.imageset/Contents.json b/GoldWars/GoldWars/Assets.xcassets/def_button.imageset/Contents.json new file mode 100644 index 0000000..f6ac2bb --- /dev/null +++ b/GoldWars/GoldWars/Assets.xcassets/def_button.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "def_button.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/GoldWars/GoldWars/Assets.xcassets/def_button.imageset/def_button.png b/GoldWars/GoldWars/Assets.xcassets/def_button.imageset/def_button.png new file mode 100644 index 0000000..b6fc30b Binary files /dev/null and b/GoldWars/GoldWars/Assets.xcassets/def_button.imageset/def_button.png differ diff --git a/GoldWars/GoldWars/Assets.xcassets/spy_button.imageset/Contents.json b/GoldWars/GoldWars/Assets.xcassets/spy_button.imageset/Contents.json new file mode 100644 index 0000000..9f41e34 --- /dev/null +++ b/GoldWars/GoldWars/Assets.xcassets/spy_button.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "spy_button.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/GoldWars/GoldWars/Assets.xcassets/spy_button.imageset/spy_button.png b/GoldWars/GoldWars/Assets.xcassets/spy_button.imageset/spy_button.png new file mode 100644 index 0000000..975c77a Binary files /dev/null and b/GoldWars/GoldWars/Assets.xcassets/spy_button.imageset/spy_button.png differ diff --git a/GoldWars/GoldWars/Components/SkillButtonNode.swift b/GoldWars/GoldWars/Components/SkillButtonNode.swift new file mode 100644 index 0000000..069b9d5 --- /dev/null +++ b/GoldWars/GoldWars/Components/SkillButtonNode.swift @@ -0,0 +1,56 @@ +// +// SkillButtonNode.swift +// GoldWars +// +// Created by Simon Kellner on 17.06.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import SpriteKit + +class SkillButtonNode: ButtonNode { + + + var cooldownCounter = 0 + var hasCooled: Bool = false + let cooldown: Int + let displayText: String + + init(textureName: String, text: String, isEnabled: Bool, cooldown: Int, position: CGPoint, onButtonPress: @escaping () -> ()) { + self.cooldown = cooldown + self.displayText = text + super.init(textureName: textureName, text: text, isEnabled: isEnabled, position: position, onButtonPress: onButtonPress) + } + + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + super.touchesBegan(touches, with: event) + super.isEnabled = false + self.cooldownCounter = self.cooldown + self.hasCooled = true + } + + func decreaseCooldown() { + if self.cooldownCounter <= 1 { + super.isEnabled = true + super.label.text = self.displayText + let newRoundAction = SKAction.sequence([ + SKAction.scale(by: 1.5, duration: 1), + SKAction.scale(by: 1/1.5, duration: 1), + ]) + if hasCooled { + self.run(newRoundAction) + self.hasCooled = false + } + } else { + super.isEnabled = false + self.cooldownCounter -= 1 + super.label.text = self.cooldownCounter.description + } + } + + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index 54793d5..659215d 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -18,9 +18,9 @@ class HUD: GKEntity { var peerLabel:SKLabelNode var peerUnitsLabel:SKLabelNode - var spySkill: SingeClickButtonNode - var defSkill: SingeClickButtonNode - var atkSkill: SingeClickButtonNode + var spySkill: SkillButtonNode + var defSkill: SkillButtonNode + var atkSkill: SkillButtonNode var roundTimerLabel: SKLabelNode let roundTimer: RoundTimer @@ -50,11 +50,12 @@ class HUD: GKEntity { self.roundTimer = RoundTimer() - spySkill = SingeClickButtonNode( - textureName: "yellow_circle", + spySkill = SkillButtonNode( + textureName: "spy_button", text: "Spy", isEnabled: true, - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + cooldown: 3, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.80, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { 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) @@ -62,11 +63,12 @@ class HUD: GKEntity { SoundManager.sharedInstance.playSoundEffect(pathToFile: "use_boost",fileExtension: "wav", volumeLevel: 0.0) } ) - defSkill = SingeClickButtonNode( - textureName: "yellow_circle", + defSkill = SkillButtonNode( + textureName: "def_button", text: "Def", isEnabled: true, - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.85, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + cooldown: 4, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.90, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { DataService.sharedInstance.localRoundData.hasDefenceBoost = true GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) @@ -74,11 +76,12 @@ class HUD: GKEntity { SoundManager.sharedInstance.playSoundEffect(pathToFile: "use_boost",fileExtension: "wav",volumeLevel: 0.0) } ) - atkSkill = SingeClickButtonNode( - textureName: "yellow_circle", + atkSkill = SkillButtonNode( + textureName: "atk_button", text: "Atk", isEnabled: true, - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + cooldown: 4, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.70, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { DataService.sharedInstance.localRoundData.hasAttackBoost = true GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) @@ -190,5 +193,12 @@ class HUD: GKEntity { ]) currentRoundLabel.run(newRoundAction) SoundManager.sharedInstance.playSoundEffect(pathToFile: "new_round", fileExtension: "wav", volumeLevel: 0.0) + self.decreaseSkillRoundCooldownCounter() + } + + func decreaseSkillRoundCooldownCounter() { + self.spySkill.decreaseCooldown() + self.atkSkill.decreaseCooldown() + self.defSkill.decreaseCooldown() } } diff --git a/GoldWars/GoldWars/GameCenterManager.swift b/GoldWars/GoldWars/GameCenterManager.swift index a29fdd2..f3b15df 100644 --- a/GoldWars/GoldWars/GameCenterManager.swift +++ b/GoldWars/GoldWars/GameCenterManager.swift @@ -100,7 +100,6 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG GKAchievement.loadAchievements { (achievements: [GKAchievement]?, err: Error?) in var achievementExists: Bool = false achievements?.forEach({ (achievement: GKAchievement) in - print(achievement.identifier) if achievement.identifier == identifier { achievementExists = true achievement.percentComplete += increasePercentComplete