Skip to content

Commit 47f910e

Browse files
committed
Update controls text on landing page to match game
1 parent 7c246bc commit 47f910e

File tree

9 files changed

+621
-50
lines changed

9 files changed

+621
-50
lines changed

app/best_times.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"best_times": [
3+
2.652199029922486,
4+
2.123164176940918,
5+
3.8849010467529297,
6+
2.477860927581787,
7+
2.616316080093384
8+
],
9+
"best_total_time": 43.95204019546509
10+
}

app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
</head>
1010
<body>
1111
<div id="app">
12+
<div id="level-indicator">Level 1</div>
1213
<div id="viewport"></div>
1314
<div id="controls">
14-
<p>WASD: Move | Q/E: Turn | SPACE: Restart (after win)</p>
15+
<p>WASD: Move | Q/E: Turn | SPACE: Next Level/Play Again (after win)</p>
1516
</div>
1617
</div>
1718
<script type="module" src="/src/main.js"></script>

app/maze_map.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
██████████
2-
██████████
3-
4-
███████ █
5-
█ █ █
6-
█ ███ ███
7-
█ █P█
8-
███ ███ █
9-
10-
████████E█
1+
████████████
2+
████████████
3+
█ █
4+
█ █ █████ █
5+
█ █ █ █
6+
█████ █ ███
7+
█ █ █ █
8+
█ █ █ ███ █
9+
█ █ █ █P█
10+
█ █████ ███
11+
12+
██E█████████

app/src-tauri/src/game.rs

Lines changed: 412 additions & 30 deletions
Large diffs are not rendered by default.

app/src-tauri/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ fn restart_game() -> String {
3636
serde_json::to_string(&game_state).unwrap()
3737
}
3838

39+
#[tauri::command]
40+
fn next_level(state_json: String) -> String {
41+
let game_state: GameState = serde_json::from_str(&state_json).unwrap();
42+
let next_state = game_state.next_level();
43+
serde_json::to_string(&next_state).unwrap()
44+
}
45+
3946
fn main() {
4047
tauri::Builder::default()
41-
.invoke_handler(tauri::generate_handler![init_game, update_game, render_frame, restart_game])
48+
.invoke_handler(tauri::generate_handler![init_game, update_game, render_frame, restart_game, next_level])
4249
.run(tauri::generate_context!())
4350
.expect("error while running tauri application");
4451
}

app/src-tauri/src/maze.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ impl Maze {
109109
while let Some(current) = stack.pop() {
110110
// Check if we've reached the exit area
111111
if current == exit ||
112-
(current.0 == exit.0 && current.1 == exit.1 - 1) ||
113-
(current.0 == exit.0 - 1 && current.1 == exit.1) {
112+
(current.0 == exit.0 && exit.1 > 0 && current.1 == exit.1 - 1) ||
113+
(exit.0 > 0 && current.0 == exit.0 - 1 && current.1 == exit.1) {
114114
exit_reached = true;
115115
}
116116

app/src/main.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
import { invoke } from '@tauri-apps/api/core';
22

3+
// Centralized color system: convert hex to RGB
4+
function hexToRgb(hex) {
5+
// Remove # if present
6+
hex = hex.replace('#', '');
7+
8+
// Handle shorthand hex (e.g., #0f0 -> #00ff00)
9+
if (hex.length === 3) {
10+
hex = hex.split('').map(char => char + char).join('');
11+
}
12+
13+
const r = parseInt(hex.substring(0, 2), 16);
14+
const g = parseInt(hex.substring(2, 4), 16);
15+
const b = parseInt(hex.substring(4, 6), 16);
16+
17+
return `${r}, ${g}, ${b}`;
18+
}
19+
20+
// Set RGB values from hex colors
21+
function updateColorRgbValues() {
22+
const root = document.documentElement;
23+
const colors = [
24+
{ hex: '#0f0', name: 'level-1' },
25+
{ hex: '#ff00ff', name: 'level-2' },
26+
{ hex: '#ff0000', name: 'level-3' },
27+
{ hex: '#9d00ff', name: 'level-4' },
28+
{ hex: '#0000ff', name: 'level-5' },
29+
];
30+
31+
colors.forEach(({ hex, name }) => {
32+
root.style.setProperty(`--${name}-rgb`, hexToRgb(hex));
33+
});
34+
}
35+
336
let gameState = null;
437
let keys = {
538
w: false,
@@ -13,12 +46,19 @@ let keys = {
1346
let mouseDeltaX = 0.0;
1447

1548
let viewport = null;
49+
let levelIndicator = null;
50+
let controls = null;
1651
let viewportWidth = 120;
1752
let viewportHeight = 40;
1853

1954
// Initialize game
2055
async function init() {
56+
// Initialize color system
57+
updateColorRgbValues();
58+
2159
viewport = document.getElementById('viewport');
60+
levelIndicator = document.getElementById('level-indicator');
61+
controls = document.getElementById('controls');
2262
if (!viewport) {
2363
console.error('Viewport element not found');
2464
return;
@@ -156,6 +196,24 @@ function displayFrame(frame) {
156196
// Use textContent - it automatically escapes HTML and preserves whitespace
157197
// CSS white-space: pre will preserve newlines and spaces
158198
viewport.textContent = frame;
199+
200+
// Update level indicator, viewport, and controls color class
201+
if (gameState) {
202+
try {
203+
const gameStateObj = JSON.parse(gameState);
204+
const level = gameStateObj.current_level || 1;
205+
if (levelIndicator) {
206+
levelIndicator.textContent = `Level ${level}`;
207+
levelIndicator.className = `level-${level}`;
208+
}
209+
viewport.className = `level-${level}`;
210+
if (controls) {
211+
controls.className = `level-${level}`;
212+
}
213+
} catch (e) {
214+
// Ignore parse errors
215+
}
216+
}
159217
}
160218

161219
// Keyboard event handlers - listen on window to catch all keys
@@ -171,9 +229,9 @@ window.addEventListener('keydown', async (e) => {
171229
}
172230

173231
if (gameStateObj && gameStateObj.has_won) {
174-
// Restart the game
175-
gameState = await invoke('restart_game');
176-
console.log('Game restarted');
232+
// Advance to next level or restart
233+
gameState = await invoke('next_level', { stateJson: gameState });
234+
console.log('Advanced to next level or restarted');
177235
e.preventDefault();
178236
return;
179237
}

app/src/style.css

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
:root {
2+
/* Level 1 - Green */
3+
--level-1-color: #0f0;
4+
5+
/* Level 2 - Pink/Magenta */
6+
--level-2-color: #ff00ff;
7+
8+
/* Level 3 - Red */
9+
--level-3-color: #ff0000;
10+
11+
/* Level 4 - Purple (deep but bright for contrast) */
12+
--level-4-color: #9d00ff;
13+
14+
/* Level 5 - Blue */
15+
--level-5-color: #1d00ff;
16+
}
17+
18+
/* RGB values are calculated from hex colors using hexToRgb() function in main.js */
19+
120
* {
221
margin: 0;
322
padding: 0;
@@ -33,23 +52,115 @@ body {
3352
overflow: hidden;
3453
border: 2px solid #0f0;
3554
padding: 10px;
36-
box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
55+
box-shadow: 0 0 20px rgba(var(--level-1-rgb), 0.3);
3756
letter-spacing: 0;
3857
word-spacing: 0;
3958
font-variant-ligatures: none;
4059
font-feature-settings: normal;
4160
outline: none;
61+
transition: color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
62+
}
63+
64+
#viewport.level-1 {
65+
color: var(--level-1-color);
66+
border-color: var(--level-1-color);
67+
box-shadow: 0 0 20px rgba(var(--level-1-rgb), 0.3);
68+
}
69+
70+
#viewport.level-2 {
71+
color: var(--level-2-color);
72+
border-color: var(--level-2-color);
73+
box-shadow: 0 0 20px rgba(var(--level-2-rgb), 0.3);
74+
}
75+
76+
#viewport.level-3 {
77+
color: var(--level-3-color);
78+
border-color: var(--level-3-color);
79+
box-shadow: 0 0 20px rgba(var(--level-3-rgb), 0.3);
80+
}
81+
82+
#viewport.level-4 {
83+
color: var(--level-4-color);
84+
border-color: var(--level-4-color);
85+
box-shadow: 0 0 20px rgba(var(--level-4-rgb), 0.3);
86+
}
87+
88+
#viewport.level-5 {
89+
color: var(--level-5-color);
90+
border-color: var(--level-5-color);
91+
box-shadow: 0 0 20px rgba(var(--level-5-rgb), 0.3);
4292
}
4393

4494
#controls {
4595
margin-top: 20px;
4696
text-align: center;
4797
color: #0f0;
4898
font-size: 14px;
49-
text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
99+
text-shadow: 0 0 10px rgba(var(--level-1-rgb), 0.5);
100+
transition: color 0.3s ease, text-shadow 0.3s ease;
50101
}
51102

52103
#controls p {
53104
margin: 0;
54105
}
55106

107+
#controls.level-1 {
108+
color: var(--level-1-color);
109+
text-shadow: 0 0 10px rgba(var(--level-1-rgb), 0.5);
110+
}
111+
112+
#controls.level-2 {
113+
color: var(--level-2-color);
114+
text-shadow: 0 0 10px rgba(var(--level-2-rgb), 0.5);
115+
}
116+
117+
#controls.level-3 {
118+
color: var(--level-3-color);
119+
text-shadow: 0 0 10px rgba(var(--level-3-rgb), 0.5);
120+
}
121+
122+
#controls.level-4 {
123+
color: var(--level-4-color);
124+
text-shadow: 0 0 10px rgba(var(--level-4-rgb), 0.5);
125+
}
126+
127+
#controls.level-5 {
128+
color: var(--level-5-color);
129+
text-shadow: 0 0 10px rgba(var(--level-5-rgb), 0.5);
130+
}
131+
132+
#level-indicator {
133+
margin-bottom: 10px;
134+
text-align: center;
135+
color: #0f0;
136+
font-size: 16px;
137+
font-weight: bold;
138+
text-shadow: 0 0 10px rgba(var(--level-1-rgb), 0.5);
139+
transition: color 0.3s ease, text-shadow 0.3s ease;
140+
}
141+
142+
#level-indicator.level-1 {
143+
color: var(--level-1-color);
144+
text-shadow: 0 0 10px rgba(var(--level-1-rgb), 0.5);
145+
}
146+
147+
#level-indicator.level-2 {
148+
color: var(--level-2-color);
149+
text-shadow: 0 0 10px rgba(var(--level-2-rgb), 0.5);
150+
}
151+
152+
#level-indicator.level-3 {
153+
color: var(--level-3-color);
154+
text-shadow: 0 0 10px rgba(var(--level-3-rgb), 0.5);
155+
}
156+
157+
#level-indicator.level-4 {
158+
color: var(--level-4-color);
159+
text-shadow: 0 0 10px rgba(var(--level-4-rgb), 0.5);
160+
}
161+
162+
#level-indicator.level-5 {
163+
color: var(--level-5-color);
164+
text-shadow: 0 0 10px rgba(var(--level-5-rgb), 0.5);
165+
}
166+

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ <h3>Rotation</h3>
319319
</ul>
320320
<h3>Game</h3>
321321
<ul>
322-
<li><kbd>SPACE</kbd> - Restart after winning</li>
322+
<li><kbd>SPACE</kbd> - Next Level/Play Again (after win)</li>
323323
</ul>
324324
</div>
325325
</section>

0 commit comments

Comments
 (0)