Skip to content

Commit 5d04338

Browse files
author
Brigit Murtaugh
committed
Fix jokes
1 parent 4c501ae commit 5d04338

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

frogger-game.html

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,33 @@ <h2 class="mb-4"><a href="#frogger-game" id="frogger-game">Frogger Game</a></h2>
293293
// Draw theme description
294294
ctx.font = 'italic 14px sans-serif';
295295
ctx.fillText(levelTheme.desc, 48, 54);
296-
// Draw dev container joke setup in the empty space within the game board (row 2)
296+
// Draw dev container joke setup in the empty space further down the game board (row 3)
297297
ctx.font = 'bold 15px sans-serif';
298298
ctx.fillStyle = '#FFD700';
299299
ctx.textAlign = 'center';
300-
// Place the joke in the center of the second row (not at the very top)
301-
ctx.fillText(levelTheme.joke, canvas.width / 2, grid + grid / 2);
300+
// Word-wrap the joke setup if it's too long for the canvas
301+
const joke = levelTheme.joke;
302+
const maxWidth = canvas.width - 48; // leave padding on both sides
303+
const words = joke.split(' ');
304+
let line = '';
305+
let lines = [];
306+
for (let n = 0; n < words.length; n++) {
307+
let testLine = line + words[n] + ' ';
308+
let metrics = ctx.measureText(testLine);
309+
let testWidth = metrics.width;
310+
if (testWidth > maxWidth && n > 0) {
311+
lines.push(line.trim());
312+
line = words[n] + ' ';
313+
} else {
314+
line = testLine;
315+
}
316+
}
317+
lines.push(line.trim());
318+
// Draw each line, vertically centered in row 3 (further down)
319+
const baseY = grid * 2 + grid / 2 - ((lines.length - 1) * 12);
320+
for (let i = 0; i < lines.length; i++) {
321+
ctx.fillText(lines[i], canvas.width / 2, baseY + i * 24);
322+
}
302323
drawFrog();
303324
drawCars();
304325
if (gameOver || showPunchline) {

0 commit comments

Comments
 (0)