Additional sounds

This commit is contained in:
Martin 2022-12-22 11:40:07 +01:00
parent c862079727
commit 28a14d379d
4 changed files with 37 additions and 0 deletions

Binary file not shown.

View File

@ -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
}
}

View File

@ -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"

View File

@ -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);
}