A classic 2D space shooter game built with Java Swing, featuring smooth gameplay, particle effects, and sound effects.
This is a 2D space shooter game where you control a spaceship and fight against enemy rockets. The game features:
- Smooth 60 FPS gameplay with optimized rendering
- Realistic physics with momentum and collision detection
- Particle explosion effects with alpha blending
- Sound effects for shooting, hits, and explosions
- Health system with visual HP bars
- Score tracking system
- A/D Keys: Rotate spaceship left/right
- Space: Accelerate forward
- J Key: Fire small bullets (rapid fire)
- K Key: Fire large bullets (powerful shots)
- Enter: Restart game after game over
- Player Ship: 50 HP, can be destroyed by enemy rockets
- Enemy Rockets: Spawn every 3 seconds from both sides, 20 HP each
- Bullets: Two types - small (5 damage) and large (20 damage)
- Collision Detection: Precise shape-based collision using Java Area class
- Explosion Effects: Multi-layered particle effects with different colors and sizes
├── Main.java # Main game window and initialization
├── PanelGame.java # Core game logic, rendering, and game loop
├── Player.java # Player spaceship with movement and shooting
├── Rocket.java # Enemy rocket AI and behavior
├── Bullet.java # Projectile system for both player and enemies
├── Effect.java # Particle explosion effects
├── HP.java # Health point system
├── HpRender.java # Health bar rendering
├── Key.java # Keyboard input handling
├── ModelBoom.java # Explosion particle model
├── Sound.java # Audio system for game sounds
├── shoot.wav # Shooting sound effect
├── hit.wav # Hit sound effect
└── destroy.wav # Destruction sound effect
- Double buffering for smooth animation
- Anti-aliasing for crisp graphics
- Affine transformations for sprite rotation
- Alpha compositing for particle effects
- Custom shape collision detection
- Multi-threaded architecture with separate threads for:
- Main game loop (60 FPS)
- Keyboard input handling
- Bullet physics
- Enemy spawning
- Frame rate limiting to maintain consistent 60 FPS
- Memory management with automatic cleanup of off-screen objects
- Java Sound API integration
- Non-blocking audio playback
- Multiple sound channels for different game events
The game features sophisticated particle effects:
- Multi-layered explosions with different particle sizes
- Color-coded effects (yellow, cyan, red, white particles)
- Alpha fading for realistic explosion dissipation
- Randomized particle distribution for natural-looking effects
Three distinct sound effects enhance the gameplay:
- Shoot Sound: Triggered when firing bullets
- Hit Sound: Played when bullets hit enemies
- Destroy Sound: Played when enemies or player are destroyed
- Java 8+ (uses modern Java features)
- Java Swing (included in JDK)
- Java Sound API (included in JDK)
-
Compile the project:
javac *.java -
Run the game:
java Main
-
Enjoy the game! Use the controls above to play.
- Survive as long as possible against waves of enemy rockets
- Score points by destroying enemy rockets
- Avoid collisions with enemy rockets to maintain your health
- Use strategy - small bullets for rapid fire, large bullets for powerful shots
This project demonstrates several advanced Java programming concepts:
- Object-oriented design with proper inheritance and encapsulation
- Game loop architecture with frame rate control
- Multi-threading for responsive gameplay
- Graphics programming with Java 2D API
- Audio programming with Java Sound API
- Mathematical calculations for physics and collision detection
This project is open source and available for educational purposes.
