Skip to content

About

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

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

116 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

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 polished, responsive analog joystick (notch / safe-area aware) streamed to the desktop in near real-time over Firebase.
  • ๐ŸŽฏ Analog, continuous-angle movement โ€” steer by angle; magnitude controls speed. No grid-snapping.
  • โš”๏ธ 2โ€“3 player versus โ€” friends scan the same QR to join; one shared fruit, distinct snake colors, bite a rival and you die โ€” last snake standing wins ("I defeatedโ€ฆ" bragging cards included).
  • ๐Ÿ”ฅ 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.
  • ๐Ÿ† Global leaderboard โ€” pick a handle and compete worldwide; see "You ranked #N globally" after every run.
  • ๐Ÿ“ณ Haptics + loss flash โ€” the phone buzzes on loss (Android; best-effort iOS) with an on-screen shake where it can't.
  • ๐Ÿคณ Flex your score โ€” share to WhatsApp, X, Facebook, or Instagram straight from your phone.
  • ๐Ÿ›ฐ๏ธ Resilient sessions โ€” presence tracking with onDisconnect, host-takeover reconcile, and stale-player eviction keep multiplayer rounds clean when a phone drops or the host refreshes.
  • โšก Offline-ready PWA โ€” installable, with a network-first service worker and an "update available" reload prompt.
  • ๐Ÿ›Ÿ Single-device fallback โ€” a localStorage mode kicks in automatically when Firebase isn't available.
  • ๐Ÿ”’ Privacy-first analytics โ€” Google Analytics 4 is off by default and never loads until you accept the consent banner (it also honors Do-Not-Track / Global Privacy Control). IP-anonymized, tagged desktop-host vs. phone-controller, 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
๐Ÿ† Trophy button (desktop) View the global Top-10 leaderboard

๐Ÿ› ๏ธ 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,firestore,database) โ€” the site and both security-rule sets ship together; the rules files in this repo are the source of truth.


๐Ÿ“ 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

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages