diff --git a/assets/Media/Audio/Sound/GP_Begin_Turn_1.wav b/assets/Media/Audio/Sound/GP_Begin_Turn_1.wav new file mode 100644 index 0000000..fa7bab8 Binary files /dev/null and b/assets/Media/Audio/Sound/GP_Begin_Turn_1.wav differ diff --git a/assets/Media/Audio/Sound/GP_Begin_Turn_1.wav.meta b/assets/Media/Audio/Sound/GP_Begin_Turn_1.wav.meta new file mode 100644 index 0000000..52d89b4 --- /dev/null +++ b/assets/Media/Audio/Sound/GP_Begin_Turn_1.wav.meta @@ -0,0 +1,14 @@ +{ + "ver": "1.0.0", + "importer": "audio-clip", + "imported": true, + "uuid": "68ebed5f-544b-4337-a49c-d4ba32e8e6a2", + "files": [ + ".json", + ".wav" + ], + "subMetas": {}, + "userData": { + "downloadMode": 0 + } +} diff --git a/assets/Scenes/Game.scene b/assets/Scenes/Game.scene index 6ab1190..c4ebf37 100644 --- a/assets/Scenes/Game.scene +++ b/assets/Scenes/Game.scene @@ -348,6 +348,14 @@ "__uuid__": "efed223f-7b17-47ad-b265-7a951ace6d85", "__expectedType__": "cc.AudioClip" }, + "playerHit": { + "__uuid__": "99fb12ce-b248-4560-85fd-c1a61689adf2", + "__expectedType__": "cc.AudioClip" + }, + "playerDeath": { + "__uuid__": "68ebed5f-544b-4337-a49c-d4ba32e8e6a2", + "__expectedType__": "cc.AudioClip" + }, "weaponSwing": { "__uuid__": "5ad08e27-4461-464a-ad19-8c933abf5a5d", "__expectedType__": "cc.AudioClip" diff --git a/assets/Scripts/Game/Audio/GameAudioAdapter.ts b/assets/Scripts/Game/Audio/GameAudioAdapter.ts index 4c7700f..456ea65 100644 --- a/assets/Scripts/Game/Audio/GameAudioAdapter.ts +++ b/assets/Scripts/Game/Audio/GameAudioAdapter.ts @@ -11,6 +11,8 @@ const { ccclass, property } = _decorator; export class GameAudioAdapter extends Component { @property(AudioClip) private music: AudioClip; @property(AudioClip) private enemyHit: AudioClip; + @property(AudioClip) private playerHit: AudioClip; + @property(AudioClip) private playerDeath: AudioClip; @property(AudioClip) private weaponSwing: AudioClip; @property(AudioClip) private xpPickup: AudioClip; @property(AudioClip) private goldPickup: AudioClip; @@ -18,14 +20,17 @@ export class GameAudioAdapter extends Component { @property(AudioClip) private levelUp: AudioClip; private audioPlayer: AudioPlayer; + private player: Player; public init(player: Player, enemyManager: EnemyManager, itemManager: ItemManager): void { AppRoot.Instance.AudioPlayer.playMusic(this.music); this.audioPlayer = AppRoot.Instance.AudioPlayer; + this.player = player; player.Weapon.WeaponStrikeEvent.on(() => this.audioPlayer.playSound(this.weaponSwing), this); player.Level.LevelUpEvent.on(() => this.audioPlayer.playSound(this.levelUp), this); + player.Health.HealthPointsChangeEvent.on(this.tryPlayPlayerHitSound, this); itemManager.PickupEvent.on(this.playPickupItemSound, this); @@ -41,6 +46,16 @@ export class GameAudioAdapter extends Component { enemy.Health.HealthPointsChangeEvent.off(this.playEnemyHitSound); } + private tryPlayPlayerHitSound(healthChange: number): void { + if (healthChange < 0) { + this.audioPlayer.playSound(this.playerHit); + } + + if (!this.player.Health.IsAlive) { + this.audioPlayer.playSound(this.playerDeath); + } + } + private playEnemyHitSound(): void { this.audioPlayer.playSound(this.enemyHit); }