Trigger sound effects
This commit is contained in:
parent
6370d40e25
commit
e53e3953dc
@ -132,6 +132,7 @@ class EntityManager {
|
|||||||
scene.addChild(spriteNode.unitcountLabel)
|
scene.addChild(spriteNode.unitcountLabel)
|
||||||
scene.addChild(spriteNode.fire)
|
scene.addChild(spriteNode.fire)
|
||||||
}
|
}
|
||||||
|
SoundManager.sharedInstance.playSoundEffect(pathToFile: "attack_base",fileExtension: "wav",volumeLevel: 5.0)
|
||||||
}
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ class HUD: GKEntity {
|
|||||||
EntityManager.gameEMInstance.getOpponentBases(for: EntityManager.gameEMInstance.getTeam()).forEach({base in base.component(ofType: TeamComponent.self)?.unitcountLabel.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)
|
||||||
|
SoundManager.sharedInstance.playSoundEffect(pathToFile: "use_boost",fileExtension: "wav", volumeLevel: 10.0)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
defSkill = SingeClickButtonNode(
|
defSkill = SingeClickButtonNode(
|
||||||
@ -70,6 +71,7 @@ class HUD: GKEntity {
|
|||||||
DataService.sharedInstance.localRoundData.hasDefenceBoost = true
|
DataService.sharedInstance.localRoundData.hasDefenceBoost = true
|
||||||
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.def.ten", increasePercentComplete: 10)
|
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.def.ten", increasePercentComplete: 10)
|
||||||
|
SoundManager.sharedInstance.playSoundEffect(pathToFile: "use_boost",fileExtension: "wav",volumeLevel: 10.0)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
atkSkill = SingeClickButtonNode(
|
atkSkill = SingeClickButtonNode(
|
||||||
@ -81,6 +83,7 @@ class HUD: GKEntity {
|
|||||||
DataService.sharedInstance.localRoundData.hasAttackBoost = true
|
DataService.sharedInstance.localRoundData.hasAttackBoost = true
|
||||||
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.atk.ten", increasePercentComplete: 10)
|
GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.atk.ten", increasePercentComplete: 10)
|
||||||
|
SoundManager.sharedInstance.playSoundEffect(pathToFile: "use_boost",fileExtension: "wav",volumeLevel: 10.0)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -186,5 +189,6 @@ class HUD: GKEntity {
|
|||||||
SKAction.scale(by: 0.5, duration: 1),
|
SKAction.scale(by: 0.5, duration: 1),
|
||||||
])
|
])
|
||||||
currentRoundLabel.run(newRoundAction)
|
currentRoundLabel.run(newRoundAction)
|
||||||
|
SoundManager.sharedInstance.playSoundEffect(pathToFile: "new_round", fileExtension: "wav", volumeLevel: 5.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ class RoundTimer: Timer {
|
|||||||
timeLeft -= 1
|
timeLeft -= 1
|
||||||
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
|
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
|
||||||
|
|
||||||
|
if 1 ... 5 ~= timeLeft {
|
||||||
|
SoundManager.sharedInstance.playSoundEffect(pathToFile: "countdown", fileExtension: "wav", volumeLevel: 5.0)
|
||||||
|
}
|
||||||
|
|
||||||
if timeLeft == 0 {
|
if timeLeft == 0 {
|
||||||
EntityManager.gameEMInstance.removeModal()
|
EntityManager.gameEMInstance.removeModal()
|
||||||
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
|
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
|
||||||
|
@ -13,7 +13,9 @@ class SoundManager {
|
|||||||
public static var sharedInstance = SoundManager()
|
public static var sharedInstance = SoundManager()
|
||||||
|
|
||||||
var audioPlayer = AVAudioPlayer()
|
var audioPlayer = AVAudioPlayer()
|
||||||
|
var effectPlayer = AVAudioPlayer()
|
||||||
var backgroundMainMenuAudio: URL?
|
var backgroundMainMenuAudio: URL?
|
||||||
|
var soundEffect: URL?
|
||||||
var isMusicPlaying = false
|
var isMusicPlaying = false
|
||||||
var isMusicEnabled = true
|
var isMusicEnabled = true
|
||||||
|
|
||||||
@ -39,6 +41,17 @@ class SoundManager {
|
|||||||
UserDefaults.standard.set(true, forKey: "noMusic")
|
UserDefaults.standard.set(true, forKey: "noMusic")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func playSoundEffect(pathToFile: String, fileExtension: String, volumeLevel: Float){
|
||||||
|
soundEffect = Bundle.main.url(forResource: pathToFile, withExtension: fileExtension)
|
||||||
|
do {
|
||||||
|
effectPlayer = try AVAudioPlayer(contentsOf: soundEffect!)
|
||||||
|
} catch {
|
||||||
|
//TODO: Add logging
|
||||||
|
}
|
||||||
|
effectPlayer.volume += volumeLevel
|
||||||
|
effectPlayer.play()
|
||||||
|
}
|
||||||
|
|
||||||
func setVolume(_ volume: Float) {
|
func setVolume(_ volume: Float) {
|
||||||
audioPlayer.volume = volume
|
audioPlayer.volume = volume
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user