A JavaFX recreation of the classic Atari Asteroids game — control a spaceship, destroy incoming asteroids, and survive as long as possible.
This project focuses on real-time game logic in Java: continuous rendering, collision detection, object state management, and keyboard-driven controls — a different skill set from CRUD/data-driven apps, centered on the JavaFX AnimationTimer / game loop pattern.
- Main menu with background image, high score display, and Start button
- Player-controlled spaceship with rotation and thrust-based movement
- Asteroids that spawn, move, rotate, and wrap around screen edges
- Shooting mechanic — spaceship fires projectiles to destroy asteroids
- Collision detection between projectiles, asteroids, and the player ship
- Score tracking as asteroids are destroyed
- Game over screen with final score and a Restart button
- High score persistence across sessions (saved to file)
- Space-themed visuals: black background with scattered stars, white/grey ship and asteroids
- Java 25
- JavaFX 21 (
Canvas/GraphicsContextfor rendering,AnimationTimerfor the game loop) - Maven (dependency management + build)
src/main/java/Asteroid/
├── AsteroidApplication.java # JavaFX entry point — main menu, game loop, game over screen
├── Character.java # Abstract base class: movement, rotation, collision, screen wrapping
├── Ship.java # Player ship (extends Character)
├── Asteroid.java # Asteroid: random spawn, rotation, movement (extends Character)
├── Projectile.java # Bullet fired by the ship (extends Character)
└── PolygonFactory.java # Generates randomized asteroid polygon shapes
src/main/resources/
└── space_background.jpg # Main menu background image
└── over_background.jpg # Game Over background image
| Key | Action |
|---|---|
| ← / → / A / D | Rotate ship |
| ↑ / W | Thrust forward |
| Space | Fire |
- Main Menu — shows game title, current high score, and a Start button
- Gameplay — black space background with stars, ship and asteroids in white/grey
- Game Over — shows final score, updates high score if beaten, Restart button to play again
Download the standalone Windows build — extract the zip and run Asteroids.exe. No Java installation required.
Characteris an abstract base class handling shared behavior — movement, rotation, screen-edge wrapping, and polygon-based collision detection (Shape.intersect) — withShip,Asteroid, andProjectileall extending it.- Asteroids spawn with random size, rotation, and velocity via
PolygonFactory, giving each one a distinct silhouette. - High score is persisted to a plain text file (
highscore.txt) and only overwritten when a new run beats the existing record. - The main menu and game-over screen reuse the same
Stage, swappingSceneobjects rather than opening new windows.
- Add difficulty scaling (asteroid speed/spawn rate increases over time)
- Add sound effects for shooting and collisions