diff --git a/public/sounds/explode.mp3 b/public/sounds/explode.mp3 new file mode 100644 index 0000000..e0d8d6a Binary files /dev/null and b/public/sounds/explode.mp3 differ diff --git a/public/sounds/hit.mp3 b/public/sounds/hit.mp3 new file mode 100644 index 0000000..dc40cf2 Binary files /dev/null and b/public/sounds/hit.mp3 differ diff --git a/src/constants/sounds.ts b/src/constants/sounds.ts index b657898..b35453b 100644 --- a/src/constants/sounds.ts +++ b/src/constants/sounds.ts @@ -1,3 +1,5 @@ export enum Sound { + Explode = 'Explode', + Hit = 'Hit', Shoot = 'Shoot', } diff --git a/src/gameobjects/bullet.ts b/src/gameobjects/bullet.ts index b388666..4c35c91 100644 --- a/src/gameobjects/bullet.ts +++ b/src/gameobjects/bullet.ts @@ -1,4 +1,4 @@ -import { Tag } from '../constants' +import { Sound, Tag } from '../constants' import type { Enemy, Player } from '../types' const BULLET_SPEED = 200 @@ -17,6 +17,7 @@ export function addBullet(player: Player) { ]) bullet.onCollide(Tag.Enemy, (enemy) => { + play(Sound.Hit) bullet.destroy() const currentEnemy = enemy as Enemy currentEnemy.hurt(BULLET_DAMAGE) diff --git a/src/gameobjects/enemy.ts b/src/gameobjects/enemy.ts index 1127f93..1c72df1 100644 --- a/src/gameobjects/enemy.ts +++ b/src/gameobjects/enemy.ts @@ -1,4 +1,4 @@ -import { Sprite, Tag } from '../constants' +import { Sound, Sprite, Tag } from '../constants' import type { Player } from '../types' enum Health { @@ -60,6 +60,7 @@ export function addEnemy(x: number, y: number, player: Player) { }) enemy.onDeath(() => { + play(Sound.Explode, { volume: 0.2 }) enemy.destroy() addKaboom(enemy.pos) }) diff --git a/src/scenes/preload.ts b/src/scenes/preload.ts index e008cb9..8c82e1f 100644 --- a/src/scenes/preload.ts +++ b/src/scenes/preload.ts @@ -14,7 +14,11 @@ scene(Scene.Preload, () => { loadSprite(name, src) }) - const sounds = [[Sound.Shoot, 'sounds/shoot.mp3']] + const sounds = [ + [Sound.Explode, 'sounds/explode.mp3'], + [Sound.Hit, 'sounds/hit.mp3'], + [Sound.Shoot, 'sounds/shoot.mp3'], + ] sounds.forEach(([name, src]) => { loadSound(name, src)