Brick Breaker
S. Y. B. Tech Computer Engineering
Mini Project
[BTECCE23401: Computer Graphics and
Gaming]
By
Atharva Galwade (31242599)
2024-2025
Pursuing in
Department of Computer Engineering
Faculty of Science & Technology
1
Vishwakarma University, Pune
Index
Sr. No. Content Page No.
1 Introduction 3
2 Algorithm & objectives 3–5
3 Code 6–9
4 Result 9 – 10
5 Conclusion 11
2
Introduction:
The Brick Breaker Game is a classic arcade-style video game
that challenges the player's reflexes and coordination. In this
mini-project, the game has been developed using Turbo C++
and the graphics library, providing a nostalgic and engaging
gameplay experience within a DOS-based environment.
The core gameplay involves a ball that continuously moves
across the screen, bouncing off walls and a movable paddle
controlled by the player. The objective is to break all the bricks
arranged at the top of the screen by directing the ball using the
paddle. If the ball touches the bottom of the screen, the player
loses a life.
This game implements essential elements of game development
such as:
Collision detection between ball, bricks, walls, and paddle
User input handling for paddle movement using keyboard
keys
Score tracking and life management
Game over and win conditions
The project provides a hands-on opportunity to understand and
implement key programming concepts like 2D graphics,
animation, game loops, and event-driven input handling, all
within the constraints of Turbo C++.
This simple yet entertaining game showcases how creative logic
and basic graphical functions can be combined to deliver a fully
functional interactive application, making it an ideal educational
tool for beginners in game development.
Basic Algorithm:
3
Step 1: Initialize Game Elements:
Set up graphics mode.
Initialize the brick grid, set paddle, and ball positions.
Step 2: Rendering:
Draw bricks, paddle, ball, and score on the screen.
Update visuals continuously on each frame.
Step 3: Ball Movement:
Update ball position by adding its velocity to x and y
coordinates.
Step 4: Wall Collision:
Reverse ball direction (ballDX, ballDY) if it hits left, right, or
top walls.
Step 5: Paddle Collision:
If the ball touches the paddle, reverse its vertical direction
(ballDY).
Step 6: Brick Collision:
If the ball hits a brick, mark it as broken, reverse ball
direction, and increase score.
Step 7: Game Over:
If the ball falls below the screen, display "GAME OVER" and
end the game.
Step 8: Paddle Movement:
Use arrow keys (left/right) to move the paddle.
Step 9: Game Loop:
Continuously update the game state (ball movement,
collisions, user input) and redraw the screen.
Add a small delay to control frame rate.
4
Objectives:
1. Create a fun and interactive Brick Breaker game.
2. Understand and implement ball and paddle
movement.
3. Detect collisions between the ball, paddle, walls,
and bricks.
4. Track and update the player's score.
5. Handle game over conditions when the ball falls
off the screen.
6. Allow the user to control the paddle using
keyboard inputs.
7. Use simple graphics to represent the game
elements.
5
Code:
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define BRICK_ROWS 4
#define BRICK_COLUMNS 8
#define BRICK_WIDTH 70
#define BRICK_HEIGHT 20
#define PADDLE_WIDTH 80
#define PADDLE_HEIGHT 10
#define BALL_RADIUS 7
int bricks[BRICK_ROWS][BRICK_COLUMNS];
int score = 0;
void drawBricks() {
for (int i = 0; i < BRICK_ROWS; i++) {
for (int j = 0; j < BRICK_COLUMNS; j++) {
if (bricks[i][j] == 1) {
setfillstyle(SOLID_FILL, RED + (i % 6));
6
bar(j * BRICK_WIDTH + 50, i * BRICK_HEIGHT + 50,
j * BRICK_WIDTH + 50 + BRICK_WIDTH - 2,
i * BRICK_HEIGHT + 50 + BRICK_HEIGHT - 2);
}
}
}
}
void initializeBricks() {
for (int i = 0; i < BRICK_ROWS; i++) {
for (int j = 0; j < BRICK_COLUMNS; j++) {
bricks[i][j] = 1;
}
}
}
void showScore() {
setcolor(WHITE);
outtextxy(10, 10, "Score:");
char buffer[10];
itoa(score, buffer, 10);
outtextxy(60, 10, buffer);
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
int paddleX = SCREEN_WIDTH / 2 - PADDLE_WIDTH / 2;
int paddleY = SCREEN_HEIGHT - 40;
int ballX = SCREEN_WIDTH / 2;
int ballY = SCREEN_HEIGHT / 2;
int ballDX = 3, ballDY = -3;
initializeBricks();
while (1) {
cleardevice();
// Draw bricks
drawBricks();
// Draw paddle
setfillstyle(SOLID_FILL, GREEN);
bar(paddleX, paddleY, paddleX + PADDLE_WIDTH, paddleY
+ PADDLE_HEIGHT);
7
// Draw ball
setfillstyle(SOLID_FILL, YELLOW);
fillellipse(ballX, ballY, BALL_RADIUS, BALL_RADIUS);
// Show score
showScore();
// Move ball
ballX += ballDX;
ballY += ballDY;
// Wall collision
if (ballX <= BALL_RADIUS || ballX >= SCREEN_WIDTH -
BALL_RADIUS)
ballDX = -ballDX;
if (ballY <= BALL_RADIUS)
ballDY = -ballDY;
// Paddle collision
if (ballY + BALL_RADIUS >= paddleY &&
ballX >= paddleX &&
ballX <= paddleX + PADDLE_WIDTH) {
ballDY = -ballDY;
}
// Brick collision
for (int i = 0; i < BRICK_ROWS; i++) {
for (int j = 0; j < BRICK_COLUMNS; j++) {
if (bricks[i][j] == 1) {
int brickX = j * BRICK_WIDTH + 50;
int brickY = i * BRICK_HEIGHT + 50;
if (ballX + BALL_RADIUS > brickX &&
ballX - BALL_RADIUS < brickX + BRICK_WIDTH
&&
ballY + BALL_RADIUS > brickY &&
ballY - BALL_RADIUS < brickY + BRICK_HEIGHT)
{
bricks[i][j] = 0;
ballDY = -ballDY;
score += 10;
8
}
}
}
}
// Game over
if (ballY > SCREEN_HEIGHT) {
setcolor(WHITE);
outtextxy(SCREEN_WIDTH / 2 - 40, SCREEN_HEIGHT / 2,
"GAME OVER");
getch();
break;
}
// Paddle movement using getch
if (kbhit()) {
char ch = getch();
if (ch == 0) {
ch = getch();
if (ch == 75) { // Left Arrow
paddleX -= 10;
if (paddleX < 0) paddleX = 0;
} else if (ch == 77) { // Right Arrow
paddleX += 10;
if (paddleX + PADDLE_WIDTH > SCREEN_WIDTH)
paddleX = SCREEN_WIDTH - PADDLE_WIDTH;
}
}
}
delay(20);
}
closegraph();
return 0;
}
Result:
9
1.Every brick contains 10 points, if the ball hits
the brick the score increases.
2.The more the Bricks you will break the more
the score will increase and the bricks go lesser
and lesser.
10
3.You must balance the ball with a green bar
known as slider below, it is control by the arrow
keys, once the ball touches the ground the
game will be over and it will display a message
like “GAME OVER” and your score.
Conclusion:
11
The Brick Breaker game is a simple yet effective
project for learning and implementing fundamental
concepts of game development. By creating this game,
we gained a deeper understanding of graphics
programming, collision detection, user input handling,
and basic game mechanics. The project allowed us to
develop a working game loop, manage game elements
like the ball, paddle, and bricks, and track the player's
progress through scoring.
This project also enhanced our C++ programming
skills, especially in working with arrays, conditionals,
and loops. Additionally, by designing the game with
simple graphics, we were able to provide an engaging
user experience while learning how to structure and
develop an interactive game. Overall, the project was a
valuable learning experience and provided hands-on
practice with core programming and game
development concepts.
12