mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-10 00:56:06 +00:00
Basic sounds
This commit is contained in:
@@ -1,19 +1,34 @@
|
||||
import { _decorator, Component, Node, AudioClip } from "cc";
|
||||
import { AppRoot } from "../../AppRoot/AppRoot";
|
||||
import { AudioPlayer } from "../../Services/AudioPlayer/AudioPlayer";
|
||||
import { ItemManager, ItemType } from "../Items/ItemManager";
|
||||
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
|
||||
import { Player } from "../Unit/Player/Player";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GameAudioAdapter")
|
||||
export class GameAudioAdapter extends Component {
|
||||
@property(AudioClip) private music: AudioClip;
|
||||
@property(AudioClip) private enemyHit: AudioClip;
|
||||
@property(AudioClip) private weaponSwing: AudioClip;
|
||||
@property(AudioClip) private xpPickup: AudioClip;
|
||||
@property(AudioClip) private goldPickup: AudioClip;
|
||||
@property(AudioClip) private healthPotionPickup: AudioClip;
|
||||
@property(AudioClip) private levelUp: AudioClip;
|
||||
|
||||
private audioPlayer: AudioPlayer;
|
||||
|
||||
public init(enemyManager: EnemyManager): void {
|
||||
public init(player: Player, enemyManager: EnemyManager, itemManager: ItemManager): void {
|
||||
AppRoot.Instance.AudioPlayer.playMusic(this.music);
|
||||
|
||||
this.audioPlayer = AppRoot.Instance.AudioPlayer;
|
||||
|
||||
player.Weapon.WeaponStrikeEvent.on(() => this.audioPlayer.playSound(this.weaponSwing), this);
|
||||
player.Level.LevelUpEvent.on(() => this.audioPlayer.playSound(this.levelUp), this);
|
||||
|
||||
itemManager.PickupEvent.on(this.playPickupItemSound, this);
|
||||
|
||||
enemyManager.EnemyAddedEvent.on(this.addEnemyListeners, this);
|
||||
enemyManager.EnemyRemovedEvent.on(this.removeEnemyListeners, this);
|
||||
}
|
||||
@@ -29,4 +44,23 @@ export class GameAudioAdapter extends Component {
|
||||
private playEnemyHitSound(): void {
|
||||
this.audioPlayer.playSound(this.enemyHit);
|
||||
}
|
||||
|
||||
private playPickupItemSound(itemType: ItemType): void {
|
||||
let clipToPlay: AudioClip;
|
||||
switch (itemType) {
|
||||
case ItemType.XP:
|
||||
clipToPlay = this.xpPickup;
|
||||
break;
|
||||
case ItemType.Gold:
|
||||
clipToPlay = this.goldPickup;
|
||||
break;
|
||||
case ItemType.HealthPotion:
|
||||
clipToPlay = this.healthPotionPickup;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
this.audioPlayer.playSound(clipToPlay);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user