A Java-based 2D space shooter game built with the Processing framework. Survive waves of enemy invaders, collect power-ups, and defeat the Giant Boss to win!
- About the Project
- Gameplay
- Features
- Tech Stack
- Project Structure
- Architecture & Design
- Getting Started
- Database Setup
- Controls
- Screenshots
- Future Improvements
- Author
Brick Invaders is a fully playable 2D arcade-style game inspired by classic Space Invaders. Developed as an object-oriented Java project, it demonstrates core OOP concepts including inheritance, interfaces, polymorphism, and game-loop architecture. The game connects to a MySQL database to persist the player's high score across sessions.
The player controls a gun at the bottom of the screen using the mouse. Waves of enemies (Chickens) scroll down from the top. The player must shoot them before they reach the bottom.
Once all Chickens are destroyed, a powerful Giant Boss appears. Defeat the Boss to win the game.
| State | Description |
|---|---|
| Start | Main menu showing the current high score |
| Game | Active gameplay with enemies, bullets, and power-ups |
| Win | Displayed when the Giant Boss is defeated |
| Lose | Displayed when the player runs out of lives or the Boss reaches the bottom |
- ๐ซ Mouse-controlled gun โ aim and shoot with precision
- ๐พ 30 waves of Chicken enemies with varying health (1โ3 hit points)
- ๐ Giant Boss with 50 HP that moves in a zigzag pattern
- โค๏ธ Heart power-ups โ collect to regain lives (up to 5)
- โญ Star power-ups โ collect for bonus score points
- ๐ Dynamic difficulty โ game speed scales with the player's score
- ๐พ Persistent high score stored in a MySQL database
- ๐ Replay system โ instantly restart from Win/Lose screen
- ๐จ Multiple backgrounds for each game state (Menu, Game, Win, Lose)
| Technology | Purpose |
|---|---|
| Java 17+ | Core programming language |
| Processing 4 | 2D rendering and game loop (PApplet) |
| MySQL 8.0 | High score persistence |
| JDBC (mysql-connector-j 8.0.33) | JavaโMySQL connectivity |
BrickInvaders/
โโโ src/
โ โโโ Main.java # Entry point, game loop, state machine
โ โโโ Gun.java # Player gun logic, collision detection, Guninterface impl
โ โโโ Guninterface.java # Interface defining core gameplay interactions
โ โโโ Bullet.java # Bullet spawning, movement, and collision with enemies
โ โโโ Chicken.java # Regular enemy โ spawning, movement, health system
โ โโโ Giant.java # Boss enemy โ zigzag movement, 50 HP
โ โโโ Heart.java # Heart power-up โ spawning and collection
โ โโโ Star.java # Star power-up โ spawning and collection
โ โโโ Background.java # Background loader and renderer for each game state
โ โโโ DataBase.java # MySQL connection, high score read/write
โโโ assets/ # Images (enemies, backgrounds, gun, bullet, UI)
โ โโโ enemy1.png โ enemy4.png
โ โโโ enemygiant.png
โ โโโ gun2.png
โ โโโ bullettwo2.png
โ โโโ Heart3.png
โ โโโ bullet11.png # Used as Star visual
โ โโโ backgroundd.jpg # Menu background
โ โโโ map1.jpg # Game background
โ โโโ backf.png # Win screen background
โ โโโ backlose.png # Lose screen background
โโโ core.jar # Processing core library
โโโ mysql-connector-j-8.0.33.jar
โโโ BrickInvaders.iml
The project follows a clean OOP architecture:
-
Guninterfaceโ defines the contract forGuninteractions:star()โ handle star collectionheart()โ handle heart collectionlose_for_chickens()โ handle collision with chicken enemieslose_for_giant()โ handle collision with the giant bosspassed()โ track enemies that pass through
-
MainextendsPAppletโ acts as the central game controller, managing all game objects viaArrayListcollections and a boolean state machine (start,game,win,lose,giant). -
Static factory methods on each entity class (
makeChickens(),makeGiants(),makeStars(),makeHearts()) handle bulk spawning with pre-calculated off-screen Y positions for smooth scroll-in animation.
setup() โ initialize DB, gun, entities, assets
โ
draw() โ called ~60fps by Processing
โโโ [start] โ render menu
โโโ [game] โ update & render all entities, check collisions
โ โ score > threshold โ increase speed
โ โ chickens empty โ spawn Giant
โ โ lives < 1 โ game over
โโโ [win] โ render win screen
โโโ [lose] โ render game over screen
mousePressed() โ route click to current game state
Collision is implemented using AABB (Axis-Aligned Bounding Box) logic directly in Gun.java and Bullet.java, with separate hit-box dimensions per entity type (Chicken: 60ร70, Giant: 90ร90).
| Action | Points |
|---|---|
| Destroy a Chicken | +15 |
| Collect a Star | +10 |
| Defeat the Giant Boss | +1000 |
| Enemy passes screen | +1 (tracked as passed) |
Final score = score + passed
- Java JDK 17 or higher
- IntelliJ IDEA (recommended) or any Java IDE
- MySQL Server 8.0
- Git
# 1. Clone the repository
git clone https://github.com/<your-username>/Brick_Invaders.git
cd Brick_Invaders/BrickInvaders
# 2. Add dependencies to your IDE's classpath:
# - core.jar (Processing)
# - mysql-connector-j-8.0.33.jar- Open the project in IntelliJ IDEA
- Add
core.jarandmysql-connector-j-8.0.33.jaras libraries (File โ Project Structure โ Libraries) - Set the working directory to
BrickInvaders/(where the image assets are located) - Run
Main.java
The game uses a MySQL database to store and retrieve the high score.
-- 1. Create the database
CREATE DATABASE highscore;
-- 2. Use the database
USE highscore;
-- 3. Create the high score table
CREATE TABLE highscore (
highScore INT NOT NULL DEFAULT 0
);
-- 4. Insert the initial record
INSERT INTO highscore (highScore) VALUES (0);Note: The default credentials in
DataBase.javaare:
- Host:
localhost:3306- Username:
root- Password:
1382Update these values in
DataBase.javato match your local MySQL setup.
| Action | Input |
|---|---|
| Move gun | Move mouse left/right |
| Shoot | Left click |
| Navigate menus | Left click on buttons |
Coming soon โ add gameplay screenshots to
/screenshotsand link them here.
- Add sound effects and background music
- Introduce multiple difficulty levels
- Add keyboard support as an alternative to mouse controls
- Implement an animated sprite system for enemies
- Add a leaderboard with multiple player names
- Package the game as a runnable
.jarfile - Migrate to a local file-based score system (no DB dependency for quick setup)
- Add unit tests for collision logic
[Your Name]
- ๐ผ LinkedIn
- ๐ GitHub
- ๐ง your.email@example.com
This project is licensed under the MIT License.
Made with โ Java and a love for retro arcade games