Skip to content

lassault/SpaceWar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Space War
Space War

Gameplay

๐Ÿš€ A space odyssey โ€” originally written in Java, now playable in the browser via Rust + WebAssembly!


Java Beer


๐ŸŒ Play Online

The game is deployed to GitHub Pages and is playable directly in your browser โ€” no install required.

โ–ถ Play Space War


๐ŸŽฎ How to Play

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!


๐Ÿ—‚๏ธ Repository Structure

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

๐Ÿฆ€ Web Version โ€” Rust + WebAssembly

Why Rust + WebAssembly?

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

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  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.

Building Locally

# 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:8080

โ˜• Original Java Version

The 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

About

๐Ÿš€ A space odyssey written in Java!

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors