From 19d79be44c6cb41dd5ac73a05a63291b890ec626 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 7 Mar 2026 00:47:01 +0100 Subject: [PATCH] Add touchscreen support for mobile play - game.rs: include MOUSE_BUTTON_LEFT in jump and restart checks; Emscripten maps single taps to mouse events so no JS glue needed - web/index.html: mobile viewport meta (no user-scalable), CSS canvas scaling (max-width/max-height 100%), touch-action:none to prevent browser consuming taps as scroll/zoom, updated hint text Co-Authored-By: Claude Sonnet 4.6 --- src/game.rs | 8 +++++--- web/index.html | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/game.rs b/src/game.rs index ca8391d..9ec0f96 100644 --- a/src/game.rs +++ b/src/game.rs @@ -31,7 +31,8 @@ impl Game { GameState::Playing => { let jump = rl.is_key_pressed(KeyboardKey::KEY_SPACE) || rl.is_key_pressed(KeyboardKey::KEY_UP) - || rl.is_key_pressed(KeyboardKey::KEY_W); + || rl.is_key_pressed(KeyboardKey::KEY_W) + || rl.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT); self.world.update(dt, jump, &self.cfg); @@ -47,6 +48,7 @@ impl Game { if rl.is_key_pressed(KeyboardKey::KEY_R) || rl.is_key_pressed(KeyboardKey::KEY_SPACE) || rl.is_key_pressed(KeyboardKey::KEY_ENTER) + || rl.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) { self.world = World::new(&self.cfg); self.state = GameState::Playing; @@ -131,7 +133,7 @@ impl Game { ); // Restart prompt - let prompt = "SPACE / R / ENTER to restart"; + let prompt = "SPACE / R / ENTER / TAP to restart"; let ps = 22; let pw = d.measure_text(prompt, ps); // Blink at ~2 Hz using the world's accumulated elapsed time. @@ -139,7 +141,7 @@ impl Game { d.draw_text(prompt, (sw - pw) / 2, panel_y + 240, ps, Color::new(160, 200, 255, 255)); } - let ctrl = "SPACE / W / UP to jump"; + let ctrl = "SPACE / W / UP / TAP to jump"; let cw = d.measure_text(ctrl, 18); d.draw_text(ctrl, (sw - cw) / 2, panel_y + 285, 18, Color::new(100, 130, 180, 255)); } diff --git a/web/index.html b/web/index.html index 0c84df9..673a89f 100644 --- a/web/index.html +++ b/web/index.html @@ -2,26 +2,37 @@ - + Endless Runner