Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Asteroids (JavaFX)

A JavaFX recreation of the classic Atari Asteroids game — control a spaceship, destroy incoming asteroids, and survive as long as possible.

Overview

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.

Features

  • 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

Tech Stack

  • Java 25
  • JavaFX 21 (Canvas / GraphicsContext for rendering, AnimationTimer for the game loop)
  • Maven (dependency management + build)

Project Structure

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

Controls

Key Action
← / → / A / D Rotate ship
↑ / W Thrust forward
Space Fire

Screens

  • 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

Download the standalone Windows build — extract the zip and run Asteroids.exe. No Java installation required.

Design Notes

  • Character is an abstract base class handling shared behavior — movement, rotation, screen-edge wrapping, and polygon-based collision detection (Shape.intersect) — with Ship, Asteroid, and Projectile all 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, swapping Scene objects rather than opening new windows.

Screenshots

Screenshot 2026-07-16 220112 Screenshot 2026-07-16 220101 Screenshot 2026-07-16 215943 Gameplay

What's Next

  • Add difficulty scaling (asteroid speed/spawn rate increases over time)
  • Add sound effects for shooting and collisions

About

A JavaFX recreation of the classic Atari Asteroids game — control a spaceship, destroy incoming asteroids, and survive as long as possible.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages