Skip to content

gitflarePublicPartly agent-ready40

orbit-duel

Real-time two-player orbital combat game on Cloudflare Workers and Durable Objects.

main
Add the Apache-2.0 licence0413e56
Markdown61 lines3.3 KB

Orbit Duel

Real-time multiplayer space dogfight for 2-8 pilots: ships with inertia orbit a central planet in a wrap-around 1600x1600 world. One Cloudflare Worker with static assets, Durable Objects and D1.

How to play

  • Keyboard: A/D or arrows rotate, W or Up thrust, Space fire, Tab scoreboard, F3 debug.
  • Touch: left stick aims and thrusts, right button fires. Landscape is best.
  • 3 hits destroy a ship; the planet kills too. Respawn after 3 s with 2 s invulnerability. Power-ups: shield, triple shot, rapid fire.
  • First to 10 kills or 4 minutes wins; results show kills, deaths and accuracy, then a rematch starts.
  • Quick play joins the fullest open room; Create private room gives a link like /r/ABC234. Opening that link shows a join sheet over a live view of the room.

Run

npm install
npx wrangler d1 migrations apply DB --local   # optional: local leaderboard table
npm run dev
npm test
npm run bots -- http://localhost:8787 --bots 3 --seconds 20

The leaderboard also creates its table on first use (CREATE TABLE IF NOT EXISTS, same schema as migrations/0001_init.sql) and degrades to "unavailable" without a DB.

Architecture

  • src/index.ts routes: /health, POST /api/rooms, /api/quickplay, /api/leaderboard?mode=duel, /ws/<CODE>; everything else is static assets (SPA fallback for /r/<CODE>).
  • src/room.ts Room Durable Object: 30 Hz alarm loop, hibernation WebSockets, token-bucket rate limit, per-client delta snapshots. src/lobby.ts tracks rooms (players = connected player slots) for quick play and live counts.
  • public/shared/ sim, rng and protocol shared by server, browser and tests. Bullets are never in snapshots: clients simulate them from fire events.

Protocol (compact JSON arrays)

Client: ["j",name,token|null,tick|null,_,watch?], ["i",seq,rotate,thrust,fire,ackTick], ["a",tick], ["p",ms]. Server: ["w",...] welcome, ["s",tick,baseTick,lastInputSeq,delta], ["o",ms,tick], ["v",tick,...events], ["e",code,msg].

File map

  • public/app.js, index.html, style.css, _headers: landing, join sheet, HUD, CSP.
  • public/net.js, render.js, input.js, fx.js, audio.js: client networking, canvas, input, particles, sound.
  • scripts/bots.mjs: load-test bots. tests/: node:test suites.

How to play

Duel in orbit around a planet. 3 hits destroy a ship; the planet is lethal. First to 10 kills (or most after 4 min) wins; a results screen shows a podium and accuracy, then a new match starts.

Controls: A/D or ←/→ rotate, W/↑ thrust, Space fire, Tab scoreboard, mute button in the HUD. Touch: left stick aims and thrusts, right button fires, Scores button toggles the scoreboard.

Architecture (text)

browser: input.js -> app.js -> net.js <== WebSocket ==> Worker (src/index.ts)
            render.js/fx.js/audio.js              \-> Durable Object room (src/room.ts)
                                                       runs shared/sim.js at 30 Hz

Protocol summary

Client sends inputs {rotate,thrust,fire} with seq and snapshot-tick ack. Server sends welcome, full/delta snapshots and ["v", tick, ...events] (fire, hit, kill, crash, respawn, power, pickup, phase, results). Bullets are simulated client-side from fire events.

Measured performance

MetricValue
Client fpsTBD
Server tick msTBD
Bandwidth per clientTBD