Skip to content

Commit a207264

Browse files
committed
fixed sounds being played after a level is finished
1 parent 691a48e commit a207264

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

frontend/javascript/level.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ let startY = 0
7676

7777
playAgain.addEventListener("click", () => {
7878
winScreen.classList.add("hidden")
79+
window.dispatchEvent(new CustomEvent("level:restart"))
7980
})
8081

8182
window.addEventListener("level:finished", () => {

frontend/javascript/platformer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ function updatePhysics(dt) {
992992

993993
let maxPush = 0.5
994994
while (checkCollision(dt, player.x + offX + (dir * maxPush), player.y + offY, player.hitboxW, player.hitboxH, true) && maxPush < player.tileSize) {
995-
maxPush += 2
995+
maxPush *= 2
996996
}
997997

998998
let minPush = 0
@@ -1030,9 +1030,9 @@ function updatePhysics(dt) {
10301030
const relativeY = centerY % player.tileSize
10311031
}
10321032

1033-
let maxPush = 0.5
1033+
let maxPush = 0.05
10341034
while (checkCollision(dt, player.x + offX + 0.05, player.y + offY + (dir * maxPush), player.hitboxW - 0.1, player.hitboxH, true) && maxPush < player.tileSize) {
1035-
maxPush += 0.5
1035+
maxPush *= 2
10361036
}
10371037

10381038
let minPush = 0

frontend/javascript/site.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import { state } from "./state.js"
99
import { play } from "./api.js";
1010
import { drawMinimap } from "./renderer.js";
1111

12-
const { editor } = state
12+
const { editor, player } = state
1313
export let mode = "editor"
1414

1515
export const inEditor = !window.location.pathname.startsWith("/level")
1616

1717
export function endLevel() {
1818
window.dispatchEvent(new CustomEvent("level:finished"))
19+
player.mute = true
1920
mode = inEditor ? "editor" : "play"
2021
setTimeout(inEditor ? initEditor : initPlatformer, 1)
2122
playSound("/assets/audio/victory.wav")
@@ -30,6 +31,10 @@ export function endLevel() {
3031
}
3132
}
3233

34+
window.addEventListener("level:restart", () => {
35+
player.mute = false
36+
})
37+
3338
export const input = {
3439
x: 0,
3540
y: 0,
@@ -141,6 +146,7 @@ async function preloadSound(url) {
141146
}
142147

143148
export function playSound(url, randomness = 0) {
149+
if (player.mute) return
144150
if (audioCtx.state === 'suspended') audioCtx.resume()
145151

146152
const buffer = soundbuffers.get(url)
@@ -163,4 +169,4 @@ export function playSound(url, randomness = 0) {
163169
gainNode.connect(audioCtx.destination)
164170

165171
source.start(0)
166-
}
172+
}

frontend/javascript/state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export const state = {
9595
}
9696
],
9797
player: {
98+
mute: false,
9899
requireCoins: false,
99100
coinsInLevel: 0,
100101
movingBlocks: [],

todo.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
- trigger detection
44
- add trigger limit
5+
- you can still move after the level ends, leading to sfx playing after the level is won
6+
7+
**UI**
8+
9+
- general all around polish
10+
- refactor styles
511

612
**Platformer**
713

814
- parallax background
915
- enemy texture
1016
- lava, water, ladders
1117
- debug mode where I can see variables at runtime
18+
- better SFX
19+
- walljump sticks to wall (default option)
1220

1321
**Level Share**
1422

@@ -27,3 +35,7 @@
2735
**Documentation**
2836

2937
- trigger storage
38+
39+
**Trigger Script**
40+
41+
- add some more little

0 commit comments

Comments
 (0)