Skip to content

Commit 0c382f6

Browse files
feat(public): add click and splash sounds
1 parent cc01921 commit 0c382f6

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed
File renamed without changes.

public/sounds/splash.mp3

38.4 KB
Binary file not shown.

src/constants/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './pipes'
22
export * from './scenes'
3+
export * from './sounds'
34
export * from './tags'
45
export * from './tiles'

src/constants/sounds.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum Sound {
2+
click = 'click',
3+
splash = 'splash',
4+
}

src/scenes/game.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EmptyToFilledPipe, Scene, Tag } from '../constants'
1+
import { EmptyToFilledPipe, Scene, Sound, Tag } from '../constants'
22
import { checkSolution, rotatePipe } from '../helpers'
33
import { getLevel, hasLevel } from '../levels'
44

@@ -17,10 +17,13 @@ scene(Scene.game, (levelNumber: number) => {
1717

1818
onClick(Tag.pipe, (pipe) => {
1919
if (!checkSolution(level)) {
20+
play(Sound.click)
2021
rotatePipe(pipe)
2122
}
2223

2324
if (checkSolution(level)) {
25+
play(Sound.splash)
26+
2427
level.get(Tag.pipe).forEach((pipe) => {
2528
pipe.use(
2629
sprite(

src/scenes/preload.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { pipes, Scene } from '../constants'
1+
import { pipes, Scene, Sound } from '../constants'
22

33
scene(Scene.preload, async () => {
4-
await Promise.all(
5-
pipes.map((value) => {
6-
loadSprite(value, `sprites/pipes/${value}.png`)
7-
}),
8-
)
4+
const sprites = pipes.map((pipe) => {
5+
loadSprite(pipe, `sprites/pipes/${pipe}.png`)
6+
})
7+
8+
const sounds = Object.values(Sound).map((sound) => {
9+
loadSound(sound, `sounds/${sound}.mp3`)
10+
})
11+
12+
await Promise.all(sprites.concat(sounds))
913

1014
go(Scene.game, new URLSearchParams(location.search).get('level') || 0)
1115
})

0 commit comments

Comments
 (0)