Skip to content

Commit

Permalink
chore(sounds): play hit and explode
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 23, 2025
1 parent 30db74a commit 1cb4cac
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
Binary file added public/sounds/explode.mp3
Binary file not shown.
Binary file added public/sounds/hit.mp3
Binary file not shown.
2 changes: 2 additions & 0 deletions src/constants/sounds.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export enum Sound {
Explode = 'Explode',
Hit = 'Hit',
Shoot = 'Shoot',
}
3 changes: 2 additions & 1 deletion src/gameobjects/bullet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tag } from '../constants'
import { Sound, Tag } from '../constants'
import type { Enemy, Player } from '../types'

const BULLET_SPEED = 200
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/gameobjects/enemy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Sprite, Tag } from '../constants'
import { Sound, Sprite, Tag } from '../constants'
import type { Player } from '../types'

enum Health {
Expand Down Expand Up @@ -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)
})
Expand Down
6 changes: 5 additions & 1 deletion src/scenes/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1cb4cac

Please sign in to comment.