Space War
๐ A space odyssey โ originally written in Java, now playable in the browser via Rust + WebAssembly!
The game is deployed to GitHub Pages and is playable directly in your browser โ no install required.
| Action | Control |
|---|---|
| Move ship | Mouse (or touch-drag on mobile) |
| Fire | Spacebar (or tap on mobile) |
| Select ship | Keys 1 โ 8 |
The ship upgrades automatically as your score increases every 250 points (up to level 8). Destroy enemies to earn points; survive with your 3 lives!
SpaceWar/
โโโ src/lassa/net/ # Original Java source (Swing/AWT desktop app)
โ โโโ imagenes/ # All game sprites (shared with web version)
โโโ spacewar-wasm/ # Rust + WebAssembly rewrite
โ โโโ src/lib.rs # Complete game logic in Rust
โ โโโ Cargo.toml
โ โโโ www/ # Web-deployable folder
โ โโโ index.html # Game page (single file, no bundler needed)
โ โโโ assets/ # Sprites served as static files
โโโ .github/workflows/
โโโ deploy-pages.yml # CI/CD: builds WASM โ deploys to GitHub Pages
| Concern | Answer |
|---|---|
| Performance | Rust compiles to near-native speed WASM; no GC pauses |
| Safety | Memory-safe by default โ no null-pointer crashes |
| Portability | Runs in any modern browser without plugins |
| Portfolio fit | Demonstrates both systems programming and web skills |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Browser โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โ
โ โ index.html โ โ spacewar_wasm โ โ
โ โ (JS glue) โโโโ .wasm (54 KB)โ โ
โ โ โ โ โ โ
โ โ โข load imgs โ โ โข game state โ โ
โ โ โข RAF loop โ โ โข physics โ โ
โ โ โข events โ โ โข collisions โ โ
โ โโโโโโโโฌโโโโโโโ โ โข rendering โ โ
โ โ Canvas โ (web-sys) โ โ
โ โโโโโโโโโโบโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
SpaceWarGame::tick(timestamp)โ called each animation frame; runs all physics, AI, and renders to the HTML5 Canvas.SpaceWarGame::on_key_down(key, code)โ keyboard input forwarded from JS.SpaceWarGame::on_mouse_move(x, y)โ mouse/touch position forwarded from JS.
# Prerequisites: Rust stable, wasm-pack
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
# Build
cd spacewar-wasm
wasm-pack build --target web --out-dir www/pkg
# Serve (any static file server works)
cd www
python3 -m http.server 8080
# Open http://localhost:8080The original desktop game (src/) is a pure Java Swing/AWT application using multi-threading for movement, collision detection, enemy generation, and rendering.
# Run the pre-built JAR
java -jar SpaceWar.jar