-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSounds.ts
More file actions
30 lines (24 loc) · 932 Bytes
/
Copy pathSounds.ts
File metadata and controls
30 lines (24 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
export class Sounds {
private explosion: Phaser.Sound.BaseSound | undefined;
private torpedo: Phaser.Sound.BaseSound | undefined;
constructor(private readonly gameEvents: Phaser.Events.EventEmitter) {
gameEvents.on('torpedo-launched', (isPlayer: boolean) => this.onTorpedoLaunched(isPlayer));
gameEvents.on('player-exploded', () => this.onPlayerExploded());
}
public preload(scene: Phaser.Scene) {
scene.load.audio('explosion', 'assets/sounds/explosion.mp3');
scene.load.audio('torpedo', 'assets/sounds/torpedo.mp3');
}
public create(scene: Phaser.Scene) {
this.explosion = scene.sound.add('explosion');
this.torpedo = scene.sound.add('torpedo');
}
private onTorpedoLaunched(isPlayer: boolean) {
if (isPlayer) {
this.torpedo?.play();
}
}
private onPlayerExploded() {
this.explosion?.play();
}
}