Skip to content

nocoo/pew-game

Repository files navigation

pew.md

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.

Play now β†’ pew.md

pew.md gameplay

Play

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-ups (wave 3+, 25% drop on kill)

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

Tech stack

  • Runtime: Bun
  • Framework: Next.js 16 (App Router)
  • Language: TypeScript 6 (strict mode)
  • Styling: Tailwind CSS 4
  • Database: SQLite via better-sqlite3

Architecture

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.

Development

# install
bun install

# dev server
bun dev

# lint + test
bun run check

# unit tests only
vitest run

# build
bun run build

Test coverage

73 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.

License

MIT

About

🀠 Pixel art twin-stick prairie shooter in the browser, with leaderboard and anti-cheat

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages