Skip to content

aryamangodara/snake_controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

56 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Cross-Device Snake

Play on your desktop. Steer with your phone. Scan a QR code and your phone becomes a wireless, analog joystick.

Play the live demo

PWA Vanilla JS Firebase License: MIT


๐ŸŽฎ How to play

  1. Host โ€” open the demo on a computer. A glowing QR code + 6-digit code appears.
  2. Connect โ€” scan the QR with your phone camera (or type the code). It auto-connects โ€” no app, no install.
  3. Play โ€” tap โ–ถ to start, then tilt the joystick to steer. Push further to go faster.

The snake never stops โ€” you steer it at any angle (not just up/down/left/right), and speed scales with how far you push the stick. Eat food quickly to build a ๐Ÿ”ฅ combo (up to ร—6) before the streak timer drains.


โœจ Features

  • ๐Ÿ“ฑ Phone-as-controller โ€” a custom touch joystick streamed to the desktop in near real-time over Firebase.
  • ๐ŸŽฏ Analog, continuous-angle movement โ€” steer by angle; magnitude controls speed. No grid-snapping.
  • ๐Ÿ”ฅ Combo streaks โ€” chain quick eats for a score multiplier, shown as a draining yellow timer badge.
  • ๐ŸŽ† Juice โ€” particle bursts, ripples, floating score pops, and screen shake on impact.
  • ๐Ÿ”Š Synthesized sound โ€” Web Audio SFX whose pitch climbs with your combo; one-tap mute.
  • ๐Ÿคณ Flex your score โ€” share to WhatsApp, X, Facebook, or Instagram straight from your phone.
  • โšก Offline-ready PWA โ€” installable, with a network-first service worker.
  • ๐Ÿ›Ÿ Single-device fallback โ€” a localStorage mode kicks in automatically when Firebase isn't available.
  • ๐Ÿ“Š Audience analytics โ€” Google Analytics 4 for audience + campaign insight, tagged desktop-host vs. phone-controller. IP-anonymized, and it never blocks gameplay.

๐Ÿ•น๏ธ Controls

Control Action
๐Ÿ•น๏ธ Joystick Rotate to steer (any angle) ยท push further to speed up
โ–ถ Center button Start the game (turns into ๐Ÿ while playing)
โŒจ๏ธ Space / Enter (desktop) Restart after a crash
๐Ÿ” Play Again (phone) Restart from the game-over share card

๐Ÿ› ๏ธ Tech

Vanilla JavaScript (no bundler, no modules) ยท HTML5 Canvas ยท Firebase Firestore (session + game state) + Realtime Database (joystick stream) + Analytics (GA4) ยท PWA (installable, offline shell) ยท Firebase Hosting with auto-deploy via GitHub Actions.


๐Ÿ’ป Local development

There's no build step โ€” just serve the static public/ folder.

npm install      # dev tooling only: firebase-tools, eslint, vitest, prettier
npm start        # โ†’ npx serve -s public   (http://localhost:3000)

Any static server works too, e.g. python -m http.server 8000 --directory public.

  • Open on a desktop-width window to host the game.
  • Append ?session=123456 to the URL (or open on a phone) to load the controller view in a second tab/device.
npm run lint     # ESLint
npm test         # Vitest unit tests (tests/)
npm run format   # Prettier

Deploys are automatic on push to master (GitHub Actions โ†’ firebase deploy --only hosting). Database/Firestore rules are not shipped by CI.


๐Ÿ“ Architecture

Plain <script> files share one global scope, loaded in a fixed order โ€” there's no import graph. The desktop owns the game loop, rendering, and collision; the phone captures the joystick. They pair over a 6-digit code / QR via Firebase, with a localStorage fallback for single-device use.

๐Ÿค– Full map for contributors and AI agents lives in CLAUDE.md, with a deeper index under .agent/.


๐Ÿค Contributing

PRs welcome โ€” see CONTRIBUTING.md. We use Conventional Commits (feat | fix | refactor | style) and branch as feature/โ€ฆ, bugfix/โ€ฆ, docs/โ€ฆ.


Made with โค๏ธ by Aryaman Godara ยท โญ the repo if you enjoyed it!

About

๐Ÿ A modern Snake game with cross-device multiplayer - play on desktop with mobile controller via Firebase

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors