Skip to content

Commit

Permalink
move message code to playfield
Browse files Browse the repository at this point in the history
  • Loading branch information
44100hertz committed Jan 23, 2024
1 parent 276ae63 commit 10ea327
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions games/redbricks/Playfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class Playfield {
#e_playfield;
#e_viewport;
#e_entities;
#e_status;
#eventListeners;

constructor(id, gameSize) {
Expand All @@ -28,9 +29,14 @@ export default class Playfield {
this.#rescale();

this.#e_entities = queryOrFail(`#${id} .entities`);
this.#e_status = queryOrFail(`#${id} .statusMessage div`);
this.#eventListeners = {};
}

showMessage(text) {
this.#e_status.textContent = text;
}

bindPointer(c_pointerdown, c_pointermove, getPaddlePos) {
const wrapMouse = (fn) => (ev) =>
fn(this.#clientToGamePos(new Point(ev.clientX, ev.clientY)));
Expand Down
22 changes: 11 additions & 11 deletions games/redbricks/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ addEventListener("load", load);
function load() {
const gameSize = new Point(240, 240);
const playfield = new Playfield("playfield", gameSize);
const e_message = document.querySelector(".statusMessage div");
let deathCount = 0;
let level = 1;

let startTime;
function introduceLevel() {
startTime = new Date();
e_message.textContent = `LEVEL ${level}`;
playfield.showMessage(`LEVEL ${level}`);
setTimeout(start, 1000);
}

function start() {
e_message.textContent = '';
playfield.showMessage('');
const game = new Game(playfield, gameSize, level, (status) => {
switch(status) {
case "win":
Expand All @@ -31,25 +30,24 @@ function load() {
const minutes = Math.floor(time / 1000 / 60);
const seconds = String(Math.floor((time / 1000) % 60))
.padStart(2,'0');
e_message.textContent = `
playfield.showMessage(`
Good job!
Level time: ${minutes}:${seconds}`;
Level time: ${minutes}:${seconds}`);
setTimeout(introduceLevel, 1000);
break;
case "die":
e_message.textContent = `
playfield.showMessage(`
${tips[deathCount % tips.length]}
deaths: ${deathCount+1}
`
`);
++deathCount;
setTimeout(start, 1000);
break;
case "outOfLevels":
e_message.textContent = `
playfield.showMessage(`
You won...kind of. This game is WIP!
If you'd like, email ${"ssaammpzz@gmail.com".replace("zz", "")} with level ideas.
Thanks for playing.
`
Thanks for playing.`);
}
});
}
Expand All @@ -69,13 +67,15 @@ class Game {
this.level = level;
this.ballSpeed = 1.5;

// Other settings
// Other settings, probably don't touch
this.gravity = 100;
this.maxBallSpeed = 300;
this.launchSpeed = 205;
this.paddleFriction = 0.5; // Movement affecting bounce
this.paddleSurface = 10; // Rate of paddle side shifting ball angle

this.paddleVelX = 0;

this.killBlockSpeed = 80;
this.killBlocks = [];

Expand Down

0 comments on commit 10ea327

Please sign in to comment.