A pixel art twin-stick shooter in the browser, inspired by Journey of the Prairie King from Stardew Valley.
Built with Next.js 16, Bun, TypeScript (strict mode), and Tailwind CSS 4. All sprites are drawn purely in code β no image assets.
Move with WASD or Arrow Keys. Your cowboy auto-fires in the direction you're moving. Survive waves of bandits, collect power-ups, and climb the leaderboard.
| Power-up | Effect |
|---|---|
| Spread | Fires 3 bullets in a fan pattern |
| Rapidfire | Doubles fire rate |
| Pierce | Bullets pass through enemies |
| Nuke | Instantly kills all enemies on screen |
- Runtime: Bun
- Framework: Next.js 16 (App Router)
- Language: TypeScript 6 (strict mode)
- Styling: Tailwind CSS 4
- Database: SQLite via
better-sqlite3
src/
βββ game/ # Pure TypeScript game engine (no React dependency)
β βββ types.ts # All interfaces: Player, Bullet, Enemy, PowerUp, etc.
β βββ engine.ts # Main loop, state machine, rendering
β βββ input.ts # Keyboard manager (WASD + arrows)
β βββ sprites.ts # Pixel art defined as 2D hex color arrays
β βββ player.ts # Movement, auto-fire, power-up effects
β βββ bullet.ts # Creation, movement, pierce support
β βββ enemy.ts # 3 types (basic/fast/tank), edge spawning, AI
β βββ collision.ts
β βββ wave.ts # Progressive difficulty
β βββ powerup.ts # Spawn, collect, apply, update
βββ components/ # React UI layer
β βββ GameCanvas.tsx # Canvas mount, session management
β βββ Leaderboard.tsx # Top 10 sidebar
β βββ NameInput.tsx # Game over name entry (1-6 chars)
βββ lib/ # Server-side
β βββ db.ts # SQLite schema & queries
β βββ anticheat.ts # HMAC session tokens, replay prevention
βββ app/
βββ page.tsx # Layout: game + leaderboard
βββ api/ # REST endpoints
βββ token/route.ts # GET /api/token
βββ scores/route.ts # GET & POST /api/scores
Rendering: OffscreenCanvas at native 320x320, scaled 2x to 640x640 with image-rendering: pixelated.
Anti-cheat: Server issues HMAC-signed session tokens at game start. On game over, the client submits the token with the score. The server validates the signature, checks score/wave/duration plausibility, and prevents replay attacks.
# install
bun install
# dev server
bun dev
# lint + test
bun run check
# unit tests only
vitest run
# build
bun run build73 tests across 9 files covering player mechanics, bullet physics, enemy AI, collision detection, wave progression, power-ups, anti-cheat validation, and database operations. Includes E2E game loop simulation.
