Skip to content

AmirGhz17/Brick_Invaders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Brick Invaders

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!

Java Processing MySQL License


๐Ÿ“‹ Table of Contents


๐Ÿ“– About the Project

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.


๐Ÿ•น๏ธ Gameplay

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.

Game States

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

โœจ Features

  • ๐Ÿ”ซ 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)

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿ“ Project Structure

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

๐Ÿ—๏ธ Architecture & Design

Object-Oriented Design

The project follows a clean OOP architecture:

  • Guninterface โ€” defines the contract for Gun interactions:

    • star() โ€” handle star collection
    • heart() โ€” handle heart collection
    • lose_for_chickens() โ€” handle collision with chicken enemies
    • lose_for_giant() โ€” handle collision with the giant boss
    • passed() โ€” track enemies that pass through
  • Main extends PApplet โ€” acts as the central game controller, managing all game objects via ArrayList collections 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.

Game Loop Flow

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 Detection

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).

Scoring System

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


๐Ÿš€ Getting Started

Prerequisites

  • Java JDK 17 or higher
  • IntelliJ IDEA (recommended) or any Java IDE
  • MySQL Server 8.0
  • Git

Installation

# 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

Running the Game

  1. Open the project in IntelliJ IDEA
  2. Add core.jar and mysql-connector-j-8.0.33.jar as libraries (File โ†’ Project Structure โ†’ Libraries)
  3. Set the working directory to BrickInvaders/ (where the image assets are located)
  4. Run Main.java

๐Ÿ—„๏ธ Database Setup

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.java are:

  • Host: localhost:3306
  • Username: root
  • Password: 1382

Update these values in DataBase.java to match your local MySQL setup.


๐ŸŽฎ Controls

Action Input
Move gun Move mouse left/right
Shoot Left click
Navigate menus Left click on buttons

๐Ÿ–ผ๏ธ Screenshots

Coming soon โ€” add gameplay screenshots to /screenshots and link them here.


๐Ÿ”ฎ Future Improvements

  • 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 .jar file
  • Migrate to a local file-based score system (no DB dependency for quick setup)
  • Add unit tests for collision logic

๐Ÿ‘ค Author

[Your Name]


๐Ÿ“„ License

This project is licensed under the MIT License.


Made with โ˜• Java and a love for retro arcade games

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages