0% found this document useful (0 votes)
6 views31 pages

Spandu Java Report (1)

The document is a mini project report for a 2D arcade-style shooting game titled 'Block Blaster', developed by students Sinchana K and Spandana E L at BGS Institute of Technology. The game, created using Java and the Swing library, aims to teach programming concepts through interactive gameplay where players control a shooter to eliminate descending blocks. The report includes acknowledgments, an abstract, objectives, and a detailed overview of the game's design and educational value.

Uploaded by

Prajwal Gowda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views31 pages

Spandu Java Report (1)

The document is a mini project report for a 2D arcade-style shooting game titled 'Block Blaster', developed by students Sinchana K and Spandana E L at BGS Institute of Technology. The game, created using Java and the Swing library, aims to teach programming concepts through interactive gameplay where players control a shooter to eliminate descending blocks. The report includes acknowledgments, an abstract, objectives, and a detailed overview of the game's design and educational value.

Uploaded by

Prajwal Gowda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

|| Jai Sri Gurudev ||

ADICHUNCHANAGIRI UNIVERSITY
FACULTY OF ENGINEERING, MANAGEMENT & TECHNOLOGY
BGS INSTITUTE OF TECHNOLOGY
Department of Computer Science and Engineering
(Approved by AICTE, New Delhi, Affiliated to ACU & Recognized byGovt. ofKarnataka)
BG Nagar – 571448, Nagamangala Taluk, Mandya.

A Mini Project Report


On
“BLOCK BLASTER”
Submitted in partial fulfillment for the academic year 2024-25

Bachelor of Engineering
in
Computer Science and Engineering
Submitted by,
SINCHANA K 23CSE147
SPANDANA E L 23CSE148

Under the guidance of:


Mrs. Kavyashree N
Asst. Professor, Dept. of CSE
BGSIT, B G Nagara

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


B G S INSTITUTE OF TECHNOLOGY
BG NAGAR - 571448
2024-25
|| Jai Sri Gurudev ||
ADICHUNCHANAGIRI UNIVERSITY
FACULTY OF ENGINEERING, MANAGEMENT & TECHNOLOGY
BGS INSTITUTE OF TECHNOLOGY
Department of Computer Science and Engineering
(Approved by AICTE, New Delhi, Affiliated to ACU & Recognized byGovt. ofKarnataka)
BG Nagar – 571448, Nagamangala Taluk, Mandya.

CERTIFICATE
This is to certify that the Mini Project report entitled “BLOCK BLASTER” has been
successfully carried out by Ms.Sinchana K, [23CSE147], Ms.Spandana E L[23CSE148]
a bonafide student of BGS Institute of Technology, B.G Nagar in partial fulfillment of
requirements of degree of Bachelor of Engineering in Computer Science & Engineering of
Adichunchanagiri University, B.G Nagar during the year of 2024-25. It is certified that all
corrections/suggestions indicated for the internal assessment have been incorporated in the
report deposited in the department library. The Mini Project report has been approved as it
satisfies the academic requirements in respect of Mini Project work prescribed for the
Bachelor of Engineering Degree.

Signature of the Guide: Signature of HOD:

Mrs. Kavyashree N Dr. Shashikala S V


Asst. Professor, Professor &HOD,
Dept., of CSE Dept., of CSE
BGSIT, B G Nagar BGSIT, B G Nagar

External Viva

Name of the Examiners Signature of the Examiners

1. 1.

2. 2.
ACKNOWLEDGEMENT

I would like to take this opportunity to thank a lot of eminent personalities, without whose
constant encouragement, this endeavor of mine would not have become a reality. At first, I
would like to thank the ADICHUNCHANAGIRI UNIVERSITY, for having this Project as
a part of its curriculum, which gave wonderful opportunity to work on my research and
presentation abilities and BGSIT for providing me with such excellent facilities, without
which, this project could not have acquired the shape it has now done.
I sincerely convey my regards and thanks to Dr. B N Shobha, BGSIT, BG Nagar,
Mandya, for giving me a chance to carry out and present my mini project work.

My sincere thanks to Dr. Shashikala S V, Professor & Head, CSE Department, BGSIT,
B G Nagar, Mandya, for giving me a chance to carry out mini project with all the support
and facilities.
I would like to thank Mrs. Kavyashree N, Assistant Professor, Department of CSE,
BGSIT, BG Nagar, Mandya, who stood as an excellent guide to carry out with our work
and has been always available as an expressive evaluator for the creation and correction of
the report towards my mini project. He has taken pain and time to go through my work
when needed.
My heartfelt gratitude to all the teaching and non-teaching faculties of Computer Science
and Engineering Department, BGSIT, BG Nagar, Mandya, for their support and
guidance towards the completion of my mini project work.
Finally, I would also extend my heartfelt thanks to my family members, classmates, friends
and well-wishers for their support and encouragement throughout this effort.

SINCHANA K 23CSE147

SPANDANA E L 23CSE148

i
ABSTRACT
The Block Blaster project is a 2D arcade-style shooting game developed using Java and its
built-in Swing library. The primary objective of the game is for the player to control a
horizontal shooter at the bottom of the screen and eliminate descending blocks by firing bullets.
As the player destroys blocks, their score increases, and the game continues until a block
successfully reaches the bottom of the screen, resulting in a game over. The game focuses on
basic but essential programming skills, such as GUI creation, object-oriented design, event-
driven logic, collision detection, and simple real-time animation.

This mini project is designed with the educational purpose of helping students and
beginner programmers apply theoretical concepts in a practical and enjoyable manner. Unlike
commercial games that require advanced frameworks and powerful hardware, Block Blaster is
lightweight, platform-independent, and does not require any third-party libraries—making it
easy to understand, implement, and run on any Java-supported system. The game's logic is
modular and well-structured, offering flexibility for further enhancements such as difficulty
levels, sound effects, and improved graphics.

Overall, Block Blaster demonstrates how fundamental Java programming knowledge can
be creatively applied to develop an engaging and functional desktop game. It not only serves as
an introduction to game development but also provides a solid base for exploring more
complex software and game-based applications in the future.

ii
TABLE OF CONTENTS

CONTENTS PAGE NO
ACKNOWLEDGEMENT i
ABSTRACT ii
TABLE OF CONTENTS iii
LIST OF FIGURES iv
Chapter 1: INTRODUCTION 1-6
1.1 Overview 1
1.2 ProblemStatement 2
1.3 Objectives 2-3
1.4 Existing System 3
1.4.1 Disadvantages 4
1.5 Proposing System 5
1.5.1 Advantages 5-6

Chapter 2: LITERATURE SURVEY 7-8


Chapter 3: SYSTEM REQUIREMENT ANALYSIS 9-11
3.1 Functional Requirements 9-10
3.2 Hardware Requirements 10-11
3.3 Software Requirements 11
Chapter 4: IMPLEMENTATION 12-1
4.1 Source Code 12-1
4.2 Code Explanation 17-1
Chapter 5: RESULT AND SNAPSHOTS 19- 2
5.1 Flow Chart 19
5.2 Snap Shorts 20- 2
CONCLUSION 23
FUTURE ENHANCEMENT 24
REFERENCES 25

iii
LIST OF FIGURES

Figure No. Figure Name Page No.


5.1.1 Flow Chart 19

5.2.1 Main Menu 20

5.2.2 Gameplay Screen 21


5.2.3 Score Screen 22

iv
BLOCKBLASTER 2024-25

CHAPTER 1
INTRODUCTION

1.1 OVERVIEW

The Shooting Game (Block Blaster) is a simple, interactive 2D desktop game developed using
Java programming and the Swing GUI toolkit. This project is designed to demonstrate how
core programming concepts such as event handling, object-oriented design, graphical
rendering, and animation can be applied to create a fully functional application. In this game,
the player controls a shooter located at the bottom of the screen and must fire bullets to
destroy enemy blocks that continuously fall from the top. The objective is to eliminate as
many blocks as possible without letting them reach the bottom, while maintaining a high
score.
This mini project aims to serve both as a practical demonstration of Java capabilities
and as a foundational step for students or beginners interested in game development. It
focuses on simplicity, clarity, and efficiency, ensuring that the game can run smoothly on
basic computer systems without requiring external frameworks or advanced graphics libraries.
The game logic, including collision detection, score counting, and keyboard controls, is built
entirely using Java’s standard libraries.
The Block Blaster project is not only an entertaining game but also a strong learning
tool. It introduces real-time game loop mechanics, GUI management using Swing components
like J Frame and J Panel, and integrates user interaction through Key Listener events. This
project can be further expanded with sound effects, difficulty levels, multiplayer support, and
advanced graphics, making it a flexible and scalable platform for further learning and
innovation.
Built using Java’s Swing framework, the game presents a shooter at the bottom of the
screen which the player controls using keyboard input. Enemy blocks descend from the top at
regular intervals, and the player must shoot them down to score points and prevent them from
reaching the bottom of the screen. The core gameplay revolves around fast reflexes, simple
logic, and efficient interaction between game objects through events and collision detection.
This type of game not only encourages player engagement but also introduces the developer
to essential game mechanics and real-time application behavior.

Dept of CSE, BGSIT, BG NAGARA Page 1


BLOCKBLASTER 2024-25

1.2 PROBLEM STATEMENT

In the realm of learning programming, especially object-oriented and GUI-based


programming, students often struggle to find engaging, real-world applications to practice
and apply their theoretical knowledge. Traditional console-based applications offer limited
scope for creativity and user interaction, making it difficult for beginners to remain
motivated while learning essential programming concepts such as event handling, graphical
rendering, and game logic.

There is a need for a simple, interactive, and educational game that can help learners
understand and implement core programming principles in a fun and engaging way. The
solution should involve real-time user interaction, basic animation, collision detection, and
scoring systems to give users a practical experience of developing a fully functional
graphical application.

To address this issue, this project proposes the development of a 2D Shooting Game
using Java, where the player controls a shooter to destroy falling enemy blocks. The game
must allow the player to choose different difficulty modes, respond to keyboard inputs for
movement and shooting, and handle game-over scenarios with a score-tracking system. It
should be built using Java Swing for GUI components and basic 2D graphics handling.

This project aims to provide an entertaining platform that not only serves as a
foundation for game development but also enhances the learner’s ability to design, code,
and implement object-oriented solutions using Java.

1.3 OBJECTIVES
1. To develop a simple 2D shooting game using Java and Swing:
Create an interactive game where the player controls a shooter to destroy falling enemy
blocks with bullets.
2. To enhance understanding of object-oriented programming (OOP) concepts:
Implement game features using Java classes, objects, inheritance, and encapsulation.
3. To provide an engaging way to learn GUI development in Java:
Use Java Swing components for rendering graphics, handling events, and updating the user
interface dynamically.
4. To implement real-time user interaction and event handling:
Capture keyboard inputs to control the shooter’s movement and bullet firing in real-time.

Dept of CSE, BGSIT, BG NAGARA Page 2


BLOCK BLASTER 2024-25

5. To design a score-tracking system and game modes:


Allow players to choose between different difficulty levels and display the final score upon
game over.
6. To demonstrate collision detection techniques:
Use Java’s geometric methods to detect collisions between bullets and enemy blocks
accurately.
7. To create a complete mini-project suitable for academic or learning purposes:
Build a fully functional game application that can be used as a portfolio piece or academic
submission.
8. To promote problem-solving and logical thinking skills:
Encourage critical thinking in designing the game logic, enemy behavior, and user feedback
mechanisms.

1.4 EXISTING SYTEM

In the current landscape, various 2D shooting games are already available on multiple
platforms such as desktop, web, and mobile devices. These games range from simple
arcade-style shooters to more complex versions with advanced graphics, sound effects, and
multiplayer functionalities. Many existing systems are developed using powerful game
engines like Unity, Unreal Engine, or frameworks like LibGDX and Pygame, which offer a
wide range of tools and support for high-quality game development.
However, most of these existing systems are either too complex for beginners or too
heavy to run on low-end systems. They often require high system configurations and
include features beyond the scope of introductory or academic-level projects. Additionally,
they may not provide transparency into the underlying code structure, making it difficult for
learners to understand how the game mechanics work at a foundational level.
For academic and learning purposes, there is a lack of lightweight, customizable, and
beginner-friendly shooting games developed purely in Java using standard libraries like
Swing. Existing games often don't focus on demonstrating basic programming concepts or
providing educational value in terms of code clarity and modular structure.
The Block Blaster shooting game aims to address this gap by offering a simplified,
standalone desktop application that runs efficiently on basic hardware. It focuses on clarity,
ease of development, and educational purpose, making it ideal for students or beginners in
Java programming.

Dept of CSE, BGSIT, BG NAGARA Page 3


BLOCK BLASTER 2024-25

The existing system of the Fake News Detection Application covers all essential processes
involved in identifying and managing false information across digital platforms. It is
designed to serve various content categories such as politics, health, entertainment, and
current affairs, ensuring users can validate diverse types of news. The system will process
and analyze submitted content, classify it as real or fake, store detection results, track user
queries, and generate analytical reports. It supports real-time news verification, source
tracking, and decision-making for improving awareness and promoting accurate content
sharing.

1.4.1 DISADVANTAGES

1. Limited Graphics and Animations


The game uses basic 2D graphics created with Java Swing, which limits visual appeal and
may not provide an immersive gaming experience when compared to modern game
engines.
2. Single Player Only
The game is designed for single-player mode and does not support multiplayer features or
networked gameplay, restricting competitive and cooperative interaction.
3. No Sound Effects or Music
The game lacks background music and sound effects, which can reduce the overall
excitement and engagement during gameplay.
4. No Save or Progress Tracking
There is no feature to save the player's progress or maintain a high score database, which
limits replay value and long-term motivation for players.
5. Fixed Screen Size and Layout
The game runs on a fixed-size window with limited resolution handling, making it less
adaptable to various screen sizes and modern display standards.
6. Basic AI and Gameplay Logic
Enemy movement is linear and predictable, lacking intelligent behavior or dynamic
challenges, which may reduce long-term playability.
7. No Mobile or Web Support
Since the game is built using Java Swing, it can only run on desktop platforms with Java
installed, and cannot be played on mobile devices or browsers without significant
modification.

Dept of CSE, BGSIT, BG NAGARA Page 4


BLOCK BLASTER 2024-25

1.5 PROPOSING SYSTEM

The proposed system, titled Shooting Game (Block Blaster), is a lightweight, standalone 2D
arcade-style game developed using Java and its built-in Swing library. Unlike existing complex or
resource-intensive games, this system is specifically designed for educational purposes, providing
students and beginner programmers a platform to understand and apply core programming
concepts in a fun and interactive way.
The game allows a player to control a shooter that fires bullets to destroy descending
enemy blocks. The system is event-driven and utilizes Java Swing for creating the graphical user
interface. It incorporates essential game mechanics such as real-time animation, collision
detection, score tracking, and keyboard interaction. The modular design makes it easy to
understand, modify, and extend in future developments.
The proposed system is simple to install and run on any Java-supported operating system
without the need for external libraries or advanced hardware. It does not depend on any online
connectivity or third-party services, making it ideal for both offline use and classroom
demonstrations. Additionally, the structure of the program is organized in a way that encourages
object-oriented design and clean coding practices.
In the future, the system can be enhanced with sound effects, improved graphics, level
progression, and even network-based multiplayer functionality. Overall, the Block Blaster game
provides a strong foundation for learning while also delivering an enjoyable user experience.

1.5.1 ADVANTAGES
1. Interactive Learning Tool:

This project provides a hands-on way to learn Java programming by applying theoretical
concepts in a fun, practical environment.

2. Enhances Understanding of OOP and GUI:

The game helps reinforce object-oriented programming principles and GUI development using
Java Swing, both essential for software development.

3. Real-time User Interaction:

Players experience real-time interaction with the game through responsive keyboard controls
and smooth game mechanics.

4. Simple Yet Engaging Design:

Dept of CSE, BGSIT, BG NAGARA Page 5


BLOCK BLASTER 2024-25
The game’s straightforward logic makes it accessible for beginners, while its increasing
difficulty levels keep it engaging.

5. Improves Problem-Solving Skills:

Implementing features like collision detection, score management, and input handling
boosts logical and analytical thinking.

6. Customizable and Extendable:

The project can be easily enhanced with additional features like power-ups, sound effects,
or improved graphics, encouraging further development and experimentation.

7. Useful for Academic and Portfolio Purposes:

This mini project is ideal for academic submission and can be added to a student’s
portfolio to demonstrate programming capabilities.

8. No External Libraries Required:

The game is built using only core Java and Swing, making it lightweight and easy to run
without installing third-party tools or frameworks.

9. Cross-Platform Compatibility:

As a Java application, the game can run on any operating system with a Java Virtual
Machine (JVM), ensuring wide compatibility.

Dept of CSE, BGSIT, BG NAGARA Page 6


BLOCK BLASTER 2024-25

CHAPTER 2

LITERATURE SURVEY
Game development using Java is a widely studied area in computer science education,
especially for beginners learning object-oriented programming and graphical user interfaces.
Various resources, tutorials, and prior academic mini-projects have provided strong
foundations in 2D game logic, collision detection, and interactive graphics. This project builds
upon that knowledge by designing a simple shooting game using Java Swing, intended to be
both educational and entertaining.
1. Oracle Java Documentation
Reference: https://docs.oracle.com/javase/
Abstract: The official Oracle Java documentation provides detailed explanations of Java
language syntax, Swing components, event handling, and threading. It served as a
foundational reference for implementing GUI components (JFrame, JPanel, KeyListener) and
understanding how to manage user input and real-time updates in the game.

2. Geeks for Geeks – Java Swing Tutorial


Reference: https://www.geeksforgeeks.org/java-swing/
Abstract: This tutorial offers practical examples of how to build Java desktop applications
using Swing. It explains the use of layouts, buttons, and drawing components with Graphics,
which helped structure the visual elements of the shooting game, such as drawing the shooter,
bullets, and falling blocks.

3. Stack Overflow (Community Discussions)


Reference: https://stackoverflow.com/
Abstract: Stack Overflow provided troubleshooting support for specific implementation
issues such as animation lag, collision detection accuracy, and keyboard input handling.
Community-contributed solutions were helpful for optimizing gameplay responsiveness and
solving real-time bugs.

4. W3Schools – Java Basics and GUI Programming


Reference: https://www.w3schools.com/java/
Abstract: W3Schools was used as a quick reference for Java syntax, conditional statements,
loop structures, and object-oriented programming basics. It ensured code reliability and

Dept of CSE, BGSIT, BG NAGARA Page 7


BLOCK BLASTER 2024-25
readability while implementing core game logic.

5. Tutorials Point – Java Programming


Reference: https://www.tutorialspoint.com/java/
Abstract: This site gave insights into building event-driven applications using Java. It was
especially useful for understanding how to handle user input using KeyListener and manage
timers or loops to control game flow.

Dept of CSE, BGSIT, BG NAGARA Page 8


BLOCK BLASTER 2024-25

CHAPTER 3
SYSTEM REQUIREMENT ANALYSIS

3.1 FUNCTIONAL REQUIREMENTS:


1. Game Launch and Initialization:
When the application is launched, the system should initialize all game components including the
game window, shooter, background, and enemy blocks. A welcome screen or main menu must
appear, offering options such as starting the game and selecting the difficulty level. This ensures the
player is properly introduced to the game before entering gameplay.
2. Difficulty Mode Selection:
The game should allow the player to select from at least three modes: Easy, Medium, and Hard. Each
mode will define the speed of enemy blocks and their frequency. This functionality allows users of
different skill levels to enjoy the game and introduces a level of replayability.
3. Shooter Movement:
The shooter, typically represented as a rectangle at the bottom of the screen, should respond to
keyboard inputs. The left and right arrow keys should control the horizontal movement. The
movement must be restricted within the game window’s boundaries to prevent the shooter from
going off-screen.
4. Bullet Firing Mechanism:
When the Spacebar is pressed, the shooter should fire a bullet upward. The bullet should travel
vertically and disappear either when it reaches the top of the screen or hits an enemy block. Only one
or a limited number of bullets may be allowed on screen at a time to add challenge and realism.
5. Enemy Block Generation and Movement:
Enemy blocks should be generated at the top of the game screen at regular intervals. These blocks
descend toward the shooter at a speed defined by the difficulty level. The system should continuously
generate these blocks during the game to create an ongoing challenge for the player.
6. Collision Detection System:
The game must accurately detect collisions between the bullets and the enemy blocks. When a bullet
intersects with an enemy block, both objects should disappear from the screen, and the score should
be incremented. Collision detection is typically implemented using Java's Rectangle class or
bounding box logic.
7. Score Management:
The game should maintain and display a real-time score counter on the screen. Each successful hit
should add points to the player's score. This real-time feedback motivates the player and makes the
gameplay competitive.

Dept of CSE, BGSIT, BG NAGARA Page 9


BLOCK BLASTER 2024-25

8. Game Over Condition:


The system should constantly monitor if any enemy block reaches the shooter's level or crosses the
bottom of the screen. If this happens, the game must stop, display a “Game Over” message, and
show the final score. This condition signals the end of a game session.
9. Restart Option:
After the game ends, the system should provide an option for the player to restart the game by
pressing a key (typically the ‘R’ key). On restart, all game variables (score, blocks, bullets) must be
reset, and the game should return to the difficulty selection screen.
10. Exit Functionality:
The player should be able to exit the game at any point by closing the game window or pressing a
specific key (e.g., Esc key). This functionality ensures that the user has full control over the game
application and can safely exit at any time.

3.2 HARDWARE REQUIREMENTS:

Server Requirements

The server system, if used, should be equipped with a minimum of an Intel Core i3
processor running at 2.4 GHz or higher, which is sufficient for managing application
deployment or handling backend services. At least 4 GB of RAM is recommended to ensure
smooth multitasking and handling of concurrent connections or processes. The server
should have a minimum of 10 GB of free disk space to store application files, logs, and any
user data such as high scores or game history. A stable network interface, such as Ethernet
or Wi-Fi, is essential if the game is to support online connectivity or multiplayer features.
Additionally, the server should run on a 64-bit operating system such as Windows, Linux, or
macOS, all of which are compatible with Java applications.

Client Device Requirements:

The client device, used by the player to run the game, should have at least an Intel Core i3
processor to handle Java execution and real-time gameplay. A minimum of 2 GB RAM is
required, although 4 GB is recommended for smoother performance, especially during
continuous gameplay. At least 500 MB of available storage is necessary to install Java (JDK
or JRE) and save game-related files. The device should support a display resolution of at
least 1024x768 pixels to ensure proper rendering of the game's graphical interface. A
standard QWERTY keyboard is required for user interaction, particularly for controlling the
shooter’s movement and firing bullets. The operating system must support Java, and may

Dept of CSE, BGSIT, BG NAGARA Page 10


BLOCK BLASTER 2024-25
include Windows, Linux, or macOS platforms.

3.3 SOFTWARE REQUIREMENTS:


Development Requirements
Programming Language: Java (based on your expertise)
Development Environment: IntelliJ IDEA, Eclipse, or NetBeans
Libraries/Frameworks: Java Swing or JavaFX for UI, Java 2D API for graphics
Game Logic Components: Collision detection, enemy spawning, score tracking

Runtime Requirements
Operating System: Windows, mac OS, or Linux
Minimum Hardware:
Processor: Intel Core i3 or higher
RAM: 4GB minimum, 8GB recommended
Graphics Card: Integrated GPU sufficient for 2D graphics
Java Runtime Environment (JRE): Version 8 or later

Dept of CSE, BGSIT, BG NAGARA Page 11


BLOCK BLASTER 2024-25

CHAPTER 4
IMPLEMENTATION
4.1 SOURCE CODE:
package spandana;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
public class ShootingGame extends JPanel implements KeyListener, ActionListener {
private int playerX = 300;
private final int playerWidth = 40, playerHeight = 40;

private final int bulletWidth = 5, bulletHeight = 10;


private final int enemyWidth = 40, enemyHeight = 40;
private Timer timer;
private ArrayList<Rectangle> bullets;
private ArrayList<Enemy> enemies;
private Random random;
private int score = 0;
private boolean gameOver = false;
private boolean gameStarted = false; // Mode selection screen
private int enemySpeed = 5; // Default speed
private int enemySpawnRate = 3; // Default spawn rate
public ShootingGame() {

JFrame frame = new JFrame("Shooting Game - Choose Mode");

frame.setSize(600, 400);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Dept of CSE, BGSIT, BG NAGARA Page 12


BLOCK BLASTER 2024-25
frame.add(this);
frame.addKeyListener(this);
frame.setVisible(true);
bullets = new ArrayList<>();
enemies = new ArrayList<>();
random = new Random();
timer = new Timer(30, this);
}

public void paintComponent(Graphics g) {


super.paintComponent(g);
if (!gameStarted) {
g.setColor(Color.BLACK);
g.setFont(new Font("Arial", Font.BOLD, 25));
g.drawString("Choose Game Mode:", 200, 150);
g.setFont(new Font("Arial", Font.PLAIN, 20));
g.drawString("Press 1 - Easy", 230, 190);
g.drawString("Press 2 - Medium", 230, 220);
g.drawString("Press 3 - Hard", 230, 250);
return;
}
if (gameOver) {

g.setColor(Color.RED);

g.setFont(new Font("Arial", Font.BOLD, 30));


g.drawString("GAME OVER", 220, 180);
g.drawString("Final Score: " + score, 230, 220);
g.drawString("Press R to Restart", 190, 260);
return;
}
g.setColor(Color.BLACK);
g.fillRect(playerX, 350, playerWidth, playerHeight); // Draw player

Dept of CSE, BGSIT, BG NAGARA Page 13


BLOCK BLASTER 2024-25
g.setColor(Color.RED);
for (Rectangle bullet : bullets) {

g.fillRect(bullet.x, bullet.y, bulletWidth, bulletHeight); // Draw bullets


}
// Draw enemies
for (Enemy enemy : enemies) {

g.setColor(enemy.color);
g.fillRect(enemy.x, enemy.y, enemyWidth, enemyHeight); // Square enemies
}
g.setColor(Color.BLACK);
g.drawString("Score: " + score, 10, 20);
}
public void keyPressed(KeyEvent e) {
if (!gameStarted) {
if (e.getKeyCode() == KeyEvent.VK_1) { // Easy Mode
enemySpeed = 3;
enemySpawnRate = 2;
} else if (e.getKeyCode() == KeyEvent.VK_2) { // Medium Mode
enemySpeed = 5;
enemySpawnRate = 3;
} else if (e.getKeyCode() == KeyEvent.VK_3) { // Hard Mode

enemySpeed = 7;
enemySpawnRate = 5;
}
gameStarted = true;
timer.start();
}
if (gameOver && e.getKeyCode() == KeyEvent.VK_R) {
restartGame(); // Restart if game over
}

Dept of CSE, BGSIT, BG NAGARA Page 14


BLOCK BLASTER 2024-25
if (!gameOver && gameStarted) {
if (e.getKeyCode() == KeyEvent.VK_LEFT && playerX > 0) playerX -= 10;

if (e.getKeyCode() == KeyEvent.VK_RIGHT && playerX < getWidth() -


playerWidth) playerX += 10;
if (e.getKeyCode() == KeyEvent.VK_SPACE) bullets.add(new Rectangle(playerX +
playerWidth / 2, 350, bulletWidth, bulletHeight));
}

repaint();
}
public void keyReleased(KeyEvent e) {}

public void keyTyped(KeyEvent e) {}


public void actionPerformed(ActionEvent e) {
if (!gameStarted || gameOver) return;
// Update bullet positions
Iterator<Rectangle> bulletIterator = bullets.iterator();

while (bulletIterator.hasNext()) {
Rectangle bullet = bulletIterator.next();
bullet.y -= 10;
if (bullet.y < 0) bulletIterator.remove();
}
// Add enemies randomly based on mode
if (random.nextInt(100) < enemySpawnRate) {
Color[] colors = {Color.BLUE, Color.GREEN, Color.ORANGE,
Color.MAGENTA};

enemies.add(new Enemy(random.nextInt(getWidth() - enemyWidth), 0,


enemyWidth, enemyHeight, colors[random.nextInt(colors.length)]));
}

// Update enemy positions


Iterator<Enemy> enemyIterator = enemies.iterator();
while (enemyIterator.hasNext()) {
Enemy enemy = enemyIterator.next();
enemy.y += enemySpeed;

Dept of CSE, BGSIT, BG NAGARA Page 15


BLOCK BLASTER 2024-25
// Check if enemy reaches the bottom
if (enemy.y > getHeight()) {
gameOver = true; // Game Over condition
timer.stop();
}
}
// Collision detection
for (Iterator<Rectangle> bulletItr = bullets.iterator(); bulletItr.hasNext();) {
Rectangle bullet = bulletItr.next();
for (Iterator<Enemy> enemyItr = enemies.iterator(); enemyItr.hasNext();) {
Enemy enemy = enemyItr.next();
if (bullet.intersects(new Rectangle(enemy.x, enemy.y, enemyWidth,
enemyHeight))) {
bulletItr.remove();
enemyItr.remove();
score += 10;
break;
}
}
}
repaint();
}

private void restartGame() {


gameOver = false;
score = 0;
bullets.clear();
enemies.clear();
gameStarted = false; // Restart back to mode selection
timer.stop();
repaint();
}

Dept of CSE, BGSIT, BG NAGARA Page 16


BLOCK BLASTER 2024-25
public static void main(String[] args) {
new ShootingGame();
}
class Enemy {
int x, y, width, height;
Color color;

Enemy(int x, int y, int width, int height, Color color) {


this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
}
}
}

4.2 CODE EXPLINATION:

This Java-based shooting game is a well-structured mini-project that demonstrates


fundamental concepts in game development, user interaction, and graphical rendering using
Swing and AWT. The game starts with a mode selection screen, allowing the player to
choose between Easy, Medium, or Hard difficulty. Each mode affects how quickly enemies
fall and how frequently they spawn, adding a dynamic challenge. Once the game starts, the
player controls a square character that moves left and right using the arrow keys and shoots
bullets with the spacebar. Enemies, represented as colored squares, fall from the top of the
screen, and the objective is to shoot them before they reach the bottom. If an enemy reaches
the bottom, the game ends, displaying a "Game Over" screen with the final score.
The game continuously updates using a Timer, which is responsible for moving bullets
upward, spawning enemies, and updating enemy positions. Collision detection ensures that
when bullets intersect with enemies, they disappear, and the player's score increases.
Additionally, the game implements a restart mechanism, allowing the player to press 'R' to
reset all variables and begin again from the mode selection screen. The code is well-

Dept of CSE, BGSIT, BG NAGARA Page 17


BLOCK BLASTER 2024-25
organized, with separate functions handling key events, painting the graphics, Updating

object positions, and resetting the game state.


This project is a great introduction to Java-based game programming, offering insights
into event handling, animation loops, object-oriented design, and user interaction. It is also
easily extendable—features like power-ups, different enemy behaviors, background music,
or a leaderboard could enhance the gameplay further. Overall, this mini-project balances
simplicity with engaging mechanics, making it a valuable learning experience in Java
development.

Dept of CSE, BGSIT, BG NAGARA Page 18


BLOCK BLASTER 2024-25

CHAPTER5
RESULTS AND SNAPSHORTS

5.1 FLOW CHART

5.1.1 Flow Chart

Dept of CSE, BGSIT, BG NAGARA Page 19


BLOCK BLASTER 2024-25

5.2 SNAP SHORTS

Main Menu

Figure No.5.2.1 Main Menu

The game mode selection screen for your shooting game. Players are given three difficulty
options—Easy, Medium, and Hard—each mapped to a key press (1, 2, or 3). This is an
important part of your game’s user experience, as it allows players to adjust the challenge
level based on their preferences. You might consider refining this further by adding a brief
description of what each mode entails, such as how enemy behavior or firing speed changes
across difficulties.

Dept of CSE, BGSIT, BG NAGARA Page 20


BLOCK BLASTER 2024-25

Gameplay Screen

Figure No.5.2.2 Gameplay Screen

This image appears to show your shooting game in action! There's a player-controlled
entity—likely representing the shooter—along with enemy objects on the screen. The
background is solid, and the game elements are distinguishable. Your collision detection
and enemy spawning mechanics seem to be in place, which is great. If you're looking to
refine the game further, you might consider adding visual effects—such as explosions or
flashes—when a shot lands. Sound effects could also enhance player immersion.

Dept of CSE, BGSIT, BG NAGARA Page 21


BLOCK BLASTER 2024-25

SCORE Screen

Figure No.5.2.3 Score Screen

This image shows an in-game moment from your shooting game-controlled shooter,
enemies, and bullets interacting in the game space. Your core mechanics—such as
shooting and enemy movement—seem functional. If you're looking to refine the
experience, you might consider tweaking enemy spawn rates, adjusting player movement
smoothness, or incorporating a scoring system to enhance engagement.

Dept of CSE, BGSIT, BG NAGARA Page 22


BLOCK BLASTER 2024-25

CONCLUSION
The Shooting Game (Block Blaster) project successfully demonstrates the application of core
Java programming concepts, particularly in the areas of graphical user interface design, event-
driven programming, and basic game development. Through this project, we have
implemented a fully functional 2D shooting game where the player controls a shooter,
eliminates falling enemy blocks, and aims to achieve a high score.
The project served as a valuable learning experience, enabling a practical
understanding of Java Swing components, keyboard input handling, collision detection, and
real-time animation. It also emphasized the importance of modular code design and efficient
resource management in application development. Despite some limitations, such as basic
graphics and the absence of sound or advanced AI, the game provides a strong foundation for
further development.
Overall, this mini project not only met its objectives but also opened up opportunities
for future enhancements such as multiplayer modes, score saving, advanced visuals, and
cross-platform support. It has proven to be an excellent stepping stone for exploring more
advanced topics in software and game development using Java.

Dept of CSE, BGSIT, BG NAGARA Page 23


BLOCK BLASTER 2024-25

FUTURE ENHANCEMENT

Improved Graphics and Animation


Future versions of the game can incorporate more advanced 2D or even 3D graphics using
game development libraries like JavaFX or OpenGL to enhance visual appeal and provide a
more engaging user experience.
 Sound Integration
Adding background music, shooting sound effects, and collision audio feedback will
significantly improve the gameplay atmosphere and make the experience more immersive for
players.
 Multiplayer Support
The game can be extended to include local or online multiplayer modes, allowing players to
compete or collaborate in real time using socket programming or networking APIs.
 High Score Saving and Leaderboard
Implementing a system to save scores locally or on a server will increase replay value. A
leaderboard can motivate players by encouraging competition.
 Mobile and Web Versions
Porting the game to platforms like Android, iOS, or web browsers using technologies such as
Lib GDX or JavaScript frameworks will expand its accessibility and user base.
 Power-Ups and Game Items
Introducing power-ups (e.g., double bullets, shields, slow motion) and collectible items can
make the gameplay more dynamic and challenging.
 Advanced Enemy AI
Future updates can include smarter enemy behavior such as zig-zag movement, variable
speeds, or shooting back at the player, increasing the level of difficulty and interest.
 Customization Options
Allowing players to choose different themes, shooter designs, or bullet styles can enhance
personalization and user satisfaction.
 Pause, Resume, and Settings Menu
Adding a pause/resume feature, along with a settings menu for controlling volume, difficulty,
and controls, will improve the overall user experience and professionalism of the game.
 Level-Based Progression System
Instead of a single endless mode, the game can be divided into levels with increasing
difficulty, objectives, and boss fights to make gameplay more structured and rewarding.

Dept of CSE, BGSIT, BG NAGARA Page 24


BLOCK BLASTER 2024-25

REFERENCES

[1] Java Documentation – Oracle: https://docs.oracle.com/javase/ Used for understanding


core Java concepts, Swing components, event handling, and GUI development.

[2] Geeks for Geeks – Java Swing Tutorials: https://www.geeksforgeeks.org/java-swing/


Helped in learning how to implement various Swing components like JFrame, JPanel,
KeyListener, etc.

[3] Stack Overflow – Community Programming Help: https://stackoverflow.com/


Referenced for debugging errors and improving gameplay mechanics through community
discussions.

[4] W3Schools – Java Basics: https://www.w3schools.com/java/ Used to brush up on basic


Java syntax, loops, conditionals, and object-oriented concepts.

[5] Tutorials Point – Java Programming: https://www.tutorialspoint.com/java/ Referred


for theoretical knowledge and coding examples related to event-driven programming and
GUI.

[6] Mini Project Guide/Instructor Notes


Classroom notes and guidance from instructors were used to shape the project structure and
adhere to academic requirements.

Dept of CSE, BGSIT, BG NAGARA Page 25

You might also like