Skip to content

About

Browser Space Invaders game

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

17 Commits

Folders and files

Repository files navigation

SPACE INVADERS

Browser recreation of the 1978 Taito arcade classic. Single HTML file, no dependencies, no build step.

Play: https://invaders.petrochenko.info

Part of the retro arcade collection: Tetris | Pac-Man | Space Invaders

Arcade-Accurate Mechanics

Every mechanic has been verified against the original 1978 Taito cabinet:

Formation (5x11 = 55 invaders)

Row Type Points Sprite
Top Squid 30 8px, 2-frame animation
Middle (2 rows) Crab 20 11px, 2-frame animation
Bottom (2 rows) Octopus 10 12px, 2-frame animation
  • Formation moves as a unit: step right 2px until ANY invader hits the edge, then drop 8px and reverse
  • Speed scales with remaining count -- 55 alive = slow, 1 alive = extremely fast
  • Each step plays the next note in the iconic 4-note march bass loop (C3-B2-Bb2-A2)

Player Ship

  • Horizontal movement at 2px/frame, clamped to screen edges
  • 1 bullet on screen at a time -- cannot fire until previous clears (core skill mechanic)
  • Bullet speed: 5px/frame upward

Invader Bullets

  • 3 visually distinct types: rolling (alternating dots), plunger (cross shape), squiggly (animated zigzag)
  • Max 3 on screen simultaneously
  • Speed: 2px/frame downward
  • Weighted targeting -- columns closer to the player fire more frequently (not random)
  • Bullet-bullet collision -- player bullet and invader bullet destroy each other on contact

Shields (4 destructible bunkers)

  • Pixel-level erosion: player bullets erode from top, invader bullets from bottom
  • Invaders walking through shields destroy overlapping pixels
  • Shields reset each new wave

Mystery Ship (UFO)

  • Appears every ~25 seconds, crosses the top of the screen
  • Alternates left/right direction
  • Scoring based on shot count (deterministic, not random): cycles through 100/50/50/150/100/100/50/300
  • Score popup displays briefly at hit position

Nagoya Shot & Wall of Death

Advanced technique from the original arcade:

  • When bottom-row invaders descend near player level, their bullets cannot hit the player (spawn point below player hitbox)
  • Game over only triggers when invaders reach the green ground line, not the player row
  • Enables the "wall of death" strategy: keep bottom row alive, farm UFO bonuses safely

Scoring & Lives

  • 3 lives, extra life at 1,500 points (once only)
  • Direct invader-player contact kills the player
  • Game over: all lives lost OR invaders reach ground line
  • High score persisted in localStorage

Wave Progression

  • Infinite waves, shields reset each wave
  • Each new wave starts 8px lower (capped at Y=88)
  • No "level complete" -- continuous escalation

Color Regions (Original Arcade Overlay)

The original cabinet used colored cellophane strips over a black-and-white CRT:

  • Red (top) -- UFO and score area
  • White (middle) -- invader play area
  • Green (bottom) -- shields, player, ground line

Recreated with subtle alpha overlays.

Controls

Action Desktop Mobile
Move Arrow keys / A, D LEFT / RIGHT buttons
Fire Space FIRE button
Pause Esc / P --
Help H Tap help overlay

D-pad is always visible (works with Bluetooth keyboard connected to phone).

Sound

All synthesized via Web Audio API, no audio files:

Sound Implementation
March loop 4-note square wave (C3/B2/Bb2/A2), tempo synced to invader speed
Player shoot 1200-200Hz descending square chirp
Invader death 800-100Hz sawtooth crunch
UFO siren 400+/-200Hz oscillating sine (while visible)
Player death 600-40Hz sawtooth descent (1.7s)
Extra life 4-note ascending staircase (A4/C#5/E5/A5)

Tech Stack

  • Rendering: Canvas 2D API with pixel art sprites (2D arrays)
  • Audio: Web Audio API synthesizer
  • Hosting: Cloudflare Pages
  • Size: Single index.html (~1,600 lines), zero dependencies

Responsive Layout

Device D-pad Size Notes
Small phone (< 380px) 52px Compact
Medium phone (420px+) 62px Standard
Large phone / tablet (480px+) 74px Comfortable
Desktop 52px + keyboard hint Both input methods available

Deploy

npx wrangler pages deploy . --project-name space-invaders --branch main --commit-dirty=true

Architecture

Everything lives in index.html (~1,600 lines):

  1. CSS -- responsive layout, overlays, D-pad, color scheme
  2. HTML -- canvas (224x256), score header, lives row, overlays (start/gameover/help), D-pad
  3. Sprites -- pixel art as 2D arrays: player, 3 invader types (2 frames each), UFO, explosions
  4. Constants -- dimensions, speeds, shield template, UFO score table
  5. Game State -- score, lives, wave, entities, timers, shot counter
  6. Entity Creation -- player, invader formation (5x11), shields (4 bitmaps), UFO
  7. Movement -- player (clamped), formation (step/drop/reverse), UFO (timed), bullets
  8. Collision -- AABB for bullets/invaders/UFO, pixel-level for shields, bullet-bullet, invader-player contact
  9. Shield System -- per-shield bitmap, directional erosion, invader overwrite
  10. Scoring -- per-type points, shot-count UFO cycle, extra life at 1500
  11. Drawing -- sprites, shields from bitmap, 3 bullet types, color overlays, explosions
  12. Input -- keyboard (arrows/WASD/space), D-pad (touch/pointer), pause (Esc/P), help (H)
  13. Audio -- Web Audio: march loop, shoot, death, UFO siren, extra life
  14. Game Loop -- fixed timestep (1000/60), accumulator, state machine (start/playing/paused/dead/nextwave/gameover)

Arcade Accuracy Audit

21 mechanics verified against 1978 Taito specs: 21/21 match.

Category Mechanics Verified
Movement Player clamping, invader step (2px), drop (8px), edge reversal, speed scaling
Bullets 1 player bullet, 3 invader max, 3 visual types, weighted targeting, bullet-bullet collision
Shields 4 bunkers, pixel erosion (directional), invader overwrite, wave reset
UFO 25s timing, alternating direction, shot-count scoring, score popup
Scoring Per-type points, extra life 1500, contact kill, Nagoya shot
Audio March sync, UFO siren, shoot/death/extra life sounds
Visual Color overlays, sprite animation toggle, score padding

License

For educational purposes. Space Invaders is a trademark of Taito Corporation / Square Enix.

About

Browser Space Invaders game

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages