Skip to content

Commit 98a5b9f

Browse files
author
Brigit Murtaugh
committed
levels
1 parent ce5c576 commit 98a5b9f

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

frogger-game.html

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,52 @@ <h2 class="mb-4"><a href="#frogger-game" id="frogger-game">Frogger Game</a></h2>
2424

2525

2626
function getCarsForLevel(lvl) {
27-
// Increase number of cars and speed with each level
28-
const baseCars = [
29-
{ y: 7, speed: 2 + lvl, dir: 1, positions: [0, 4] },
30-
{ y: 6, speed: 3 + Math.floor(lvl/2), dir: -1, positions: [2, 6] },
31-
{ y: 5, speed: 2 + Math.floor(lvl/2), dir: 1, positions: [1, 5] },
32-
{ y: 3, speed: 3 + lvl, dir: -1, positions: [3, 7] }
27+
// Make each level more interesting:
28+
// - Level 1: basic, slow, few cars
29+
// - Level 2: more cars, some faster
30+
// - Level 3: cars in both directions, more density
31+
// - Level 4: cars with variable speeds, some short, some long
32+
// - Level 5: cars that "blink" (disappear/reappear), and a zigzag row
33+
const carConfigs = [
34+
// Level 1
35+
[
36+
{ y: 7, speed: 2, dir: 1, positions: [0, 4] },
37+
{ y: 5, speed: 2, dir: -1, positions: [2, 6] }
38+
],
39+
// Level 2
40+
[
41+
{ y: 7, speed: 2.5, dir: 1, positions: [0, 4] },
42+
{ y: 6, speed: 3, dir: -1, positions: [2, 6] },
43+
{ y: 4, speed: 2, dir: 1, positions: [1, 5] }
44+
],
45+
// Level 3
46+
[
47+
{ y: 7, speed: 2.5, dir: 1, positions: [0, 4, 6] },
48+
{ y: 6, speed: 3.5, dir: -1, positions: [2, 5] },
49+
{ y: 5, speed: 2, dir: 1, positions: [1, 3, 7] },
50+
{ y: 3, speed: 3, dir: -1, positions: [3, 7] }
51+
],
52+
// Level 4
53+
[
54+
{ y: 7, speed: 3, dir: 1, positions: [0, 2, 6] },
55+
{ y: 6, speed: 2, dir: -1, positions: [1, 4, 7] },
56+
{ y: 5, speed: 4, dir: 1, positions: [3] },
57+
{ y: 4, speed: 2.5, dir: -1, positions: [2, 5] },
58+
{ y: 2, speed: 3, dir: 1, positions: [0, 7] }
59+
],
60+
// Level 5
61+
[
62+
{ y: 7, speed: 3.5, dir: 1, positions: [0, 2, 4, 6], blink: true },
63+
{ y: 6, speed: 2, dir: -1, positions: [1, 3, 5, 7] },
64+
{ y: 5, speed: 4, dir: 1, positions: [3, 6] },
65+
{ y: 4, speed: 2.5, dir: -1, positions: [2, 5], zigzag: true },
66+
{ y: 3, speed: 3, dir: 1, positions: [1, 7] },
67+
{ y: 2, speed: 2, dir: -1, positions: [0, 4] }
68+
]
3369
];
34-
if (lvl > 1) {
35-
// Add more cars for higher levels
36-
baseCars.push({ y: 4, speed: 2 + lvl, dir: lvl % 2 === 0 ? 1 : -1, positions: [0, 6] });
37-
}
38-
if (lvl > 2) {
39-
baseCars.push({ y: 2, speed: 3 + lvl, dir: lvl % 2 === 1 ? 1 : -1, positions: [2, 5] });
40-
}
41-
return baseCars;
70+
// Clamp to max config
71+
const config = carConfigs[Math.min(lvl - 1, carConfigs.length - 1)].map(car => ({...car}));
72+
return config;
4273
}
4374

4475
function resetGame(newLevel) {
@@ -85,12 +116,17 @@ <h2 class="mb-4"><a href="#frogger-game" id="frogger-game">Frogger Game</a></h2>
85116
function drawCars() {
86117
const toolColors = ['#0078D4', '#2496ED', '#F05032', '#222']; // VS Code, Docker, Git, Terminal
87118
const toolLabels = ['</>', '🐳', 'GIT', 'TER'];
119+
const now = Date.now();
88120
cars.forEach((carRow, i) => {
89121
carRow.positions.forEach((pos, j) => {
90-
const x = pos * grid + 5;
91-
const y = carRow.y * grid + 15;
122+
// Blinking cars: skip drawing every 500ms
123+
if (carRow.blink && Math.floor(now / 500) % 2 === 0) return;
124+
let x = pos * grid + 5;
125+
let y = carRow.y * grid + 15;
92126
const w = grid - 10;
93127
const h = grid - 30;
128+
// Zigzag: move up/down slightly
129+
if (carRow.zigzag) y += Math.sin((now/200) + j) * 8;
94130
// Pick a tool type based on row and car index
95131
const toolIdx = (i + j) % toolColors.length;
96132
ctx.fillStyle = toolColors[toolIdx];

0 commit comments

Comments
 (0)