Skip to content

Commit

Permalink
fix debug skip level
Browse files Browse the repository at this point in the history
  • Loading branch information
44100hertz committed Jan 23, 2024
1 parent 81953df commit 49c8381
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
15 changes: 8 additions & 7 deletions games/redbricks/Playfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default class Playfield {
this.#e_status.textContent = text;
}

bindEvent(ev, callback) {
this.#eventListeners[ev] = addEventListener(ev, callback);
}

bindPointer(c_pointerdown, c_pointermove, getPaddlePos) {
const wrapMouse = (fn) => (ev) =>
fn(this.#clientToGamePos(new Point(ev.clientX, ev.clientY)));
Expand All @@ -47,21 +51,18 @@ export default class Playfield {
return fn(this.#clientToGamePos(new Point(clientX, clientY)));
};

const addListener = (ev, callback) =>
(this.#eventListeners[ev] = addEventListener(ev, callback));

addListener("mousedown", wrapMouse(c_pointerdown));
addListener("mousemove", wrapMouse(c_pointermove));
this.bindEvent("mousedown", wrapMouse(c_pointerdown));
this.bindEvent("mousemove", wrapMouse(c_pointermove));

// specialized touch handlers for paddle movement
addListener(
this.bindEvent(
"touchstart",
wrapTouch((point) => {
this.touchOrigin = point.sub(getPaddlePos());
c_pointerdown(point);
})
);
addListener(
this.bindEvent(
"touchmove",
wrapTouch((point) => {
if (!this.touchOrigin) return;
Expand Down
22 changes: 13 additions & 9 deletions games/redbricks/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { tips } from "./tips.js";

addEventListener("load", load);

const DEBUG = true;

function load() {
const gameSize = new Point(240, 240);
const playfield = new Playfield("playfield", gameSize);
Expand All @@ -20,29 +22,25 @@ function load() {
setTimeout(start, 1000);
}

addEventListener("keydown", (key) => {
if (key.code === 'Digit7') {
playfield.reset();
++level;
start();
}
});

function start() {
playfield.showMessage('');
const game = new Game(playfield, gameSize, level, (status) => {
switch(status) {
case "win":
++level;
const time = (new Date()).valueOf() - startTime;
const minutes = Math.floor(time / 1000 / 60);
const seconds = String(Math.floor((time / 1000) % 60))
.padStart(2,'0');
playfield.showMessage(`
Good job!
Level time: ${minutes}:${seconds}`);
++level;
setTimeout(introduceLevel, 1000);
break;
case "skipLevel":
++level;
start();
break;
case "die":
playfield.showMessage(`
${tips[deathCount % tips.length]}
Expand Down Expand Up @@ -142,6 +140,12 @@ class Game {
this.pointermove.bind(this),
() => this.paddle.position,
);

if (DEBUG) {
this.playfield.bindEvent('keydown', (ev) => {
if(ev.code == 'Digit7') this.stopStatus = 'skipLevel'
})
}
}

update(newtime) {
Expand Down

0 comments on commit 49c8381

Please sign in to comment.