Skip to content

Make home-page snake game playable on mobile - #5

Merged
stefkn merged 8 commits into
mainfrom
feat/mobile-snake-controls
Aug 31, 2026
Merged

Make home-page snake game playable on mobile#5
stefkn merged 8 commits into
mainfrom
feat/mobile-snake-controls

Conversation

@stefkn

@stefkn stefkn commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

The ASCII snake game on the home page was keyboard-only (press 'g' to start, WASD to move), so it was unusable on mobile.

Changes

  • Added touch controls: tap to start, swipe (up/down/left/right) to steer.
  • Refactored the game loop into startGame() + move(key) so keyboard and touch share the same logic (instead of faking a KeyboardEvent for the auto-move interval).
  • Fixed a bug where #flashing was referenced but never existed in the markup, which threw a TypeError the moment the game started.
  • Fixed stale-interval restart bug: the previous game's interval now gets cleared on start/lose so the snake doesn't auto-move in an old direction.
  • Made the on-screen hint and prompt text touch-aware ('SWIPE TO MOVE' / 'tap to play').
  • Repositioned .screen-content on max-width: 700px so the game is actually visible on phones.
  • While playing, touch-action: none (toggled via a .playing class) prevents the page from scrolling/zooming during swipes.

Notes

  • The mobile repositioning is a best-effort adjustment; the decorative ASCII panel is very bespoke, so the exact on-phone placement may need a visual check.
  • The duplicate id="background" (one in index.astro, one in IndexBackground.astro) predates this change; touch listeners bind to the first (outer) element and events bubble, so it still works.

Testing

  • npx astro check — 0 errors.
  • npx astro build — succeeds; touch handlers/hints present in the bundle.

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://stefkn.github.io/me/pr-preview/pr-5/

Built to branch gh-pages at 2026-08-31 07:21 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@stefkn stefkn closed this Aug 27, 2026
@stefkn stefkn reopened this Aug 27, 2026
stefan and others added 8 commits August 31, 2026 08:15
Add touch controls (tap to start, swipe to steer) alongside the
existing keyboard input, refactor the game loop into start/move
functions, fix the missing #flashing element reference that threw on
start, and reposition the game screen on small viewports.
Render each row on its own line with white-space: pre so the
monospace grid no longer wraps mid-row and splits tiles across two
columns on mobile. Also render the initial grid on start.
Show the desktop-PC ASCII art on small screens again by wrapping
the art and game overlay in a shared .scene container that is scaled
down to fit the viewport, keeping the game rendered on the monitor
screen instead of hiding the art.
Lower the ASCII art on small screens so its top edge no longer
tucks behind the header icons, and reduce the top margin of the intro
card so the text sits closer to the game instead of leaving a large gap.
Standardize the site logo, work/posts links and theme toggle to the
same height and vertical position so the header row lines up, and hide
the 'hello world' easter-egg text so only the play prompt is shown.
@stefkn
stefkn force-pushed the feat/mobile-snake-controls branch from 236a981 to 6488c07 Compare August 31, 2026 07:20
@stefkn
stefkn merged commit fb4a2ec into main Aug 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant