Vous êtes sur la page 1sur 27

Ain Shams University

Faculty of Engineering

Dx-Ball Documentation

C++ Project for 3rd Year Mechatronics Students,

Computer Programming Department,

Faculty of Engineering,

Ain Shams University, Egypt.

Under supervision of :

Dr. Cherif Salama.

Prepared by:

Ahmed Abdelshakour Allam

Ahmed Abdelaziz Mohamed

Sherif Mostafa Eltoukhi

Mahmoud Soliman Aglan

March 5, 2011
Table of Contents

Acknowledgment

Introduction 1

Project Objective 1

Game Program 2

Game Controls 2

Game Menus & Screens 3

Game Levels 5

Game video 5

Technical Documentation (Game Program Code) 6

Contact Info 24
Acknowledgment

Special Thanks For

Dr. Cherif Salam

For all his efforts during computer programing (C++) course ,

For 3rd Year Mechatronics Department at Ain Shams university.

Leading Us to create this game between your hands.


Introduction

Dx-Ball
Dx-Ball is a freeware computer game for PC first released in 1996 by Michael P.
Welch. The game is an updated version of Amiga games called Megaball. It was
patterned after classic ball & paddle arcade games such as Breakout & Arkanoid. It
became a massive classic in the windows OS freeware gaming community during
the late 1990s. Later a level editor was made available as well.

The game is basically a Breakout clone: you bounce the ball off a paddle at the
bottom of the screen, hitting different color blocks on the top. Hitting all blocks
results in completing the level & going to the next. When you hit a brick, there is a
chance that a powerup will float downwards towards the paddle and can be picked
up by touching it with the paddle. Certain powerups have positive effects, while
others have negative, making it important to try & collect the beneficial powerups
while avoiding the negative powerups.

Project Objective

To make a simple graphics game depending of Borland Graphics Interface (BGI) library as an application for C++
programming course.

Dx-Ball Documentation 1
Game Program

In our game program we have made a four different levels,


three special special balls (powerups) , two of them are
positive balls while the left is a negative one & some other
balls with no effect as a difficulty.

Also we made a simple menus for game start, transitions


between levels & exit, to ask the user whether he wants to
continue playing or stop the program.

Special functions was added to the paddle in order to


change the ball slope according to the touch between the
ball & paddle keeping the ball speed constant.

Microsoft visual studio was the mainly used program to


create the .exe game program for Windows OS.

The game is developed using C++ programming language using Object Oriented Programming (OOP) .

Game Controls

The game is controlled using only 5 keys:

Function Key

Start a new game or go to the next N


level.

Quit the game. Esc

Start the level or use the laser. Space Bar

Move the paddle to the left , the right Left , Right Arrow
direction.

Pause the game. P

Dx-Ball Documentation 2
Game Menus & Screens

There are 4 menus on the game:

1. Main Menu Screen.

It contains hints about the special balls’


abilities & ask the user to start the game by
pressing (n) key.

2. Level Complete Screen.

It determines level completeness & ask user


whether to go to next level by pressing (n) key
or Exit Game by pressing (Esc) key.

Dx-Ball Documentation 3
3. Mission Failed Screen.

It determines that the user had failed


winning the game & ask him whether to go
to next level by pressing (n) key or Exit
Game by pressing (Esc) key.

4. Mission Accomplished Screen.

It determines that the user had finished the


game successfully, Also it contains the
game credits & ask the user whether to
Restart the game by pressing (n) key or Exit
Game by pressing (Esc) key.

Dx-Ball Documentation 4
Game Levels

The game contains 4 levels consisted of different assemblies of bricks:

1.Level 1 (The Wall) 2.Level 2 (The Monkey)

3.Level 3 (Chess) 4.Level 4 (The columns)

Game video

To see a showreel video for the game Please visit:

http://vimeo.com/20198750

Dx-Ball Documentation 5
Technical Documentation (Game Program Code)

The game program code consists of 1051 lines , wrote using C++ language as following:

#include <iostream>
#include <cmath>
#include <ctime>
#include "graphics.h"
#define LEFT_ARROW 75 // Left bottom in keyboard
#define RIGHT_ARROW 77 // Right bottom in keyboard
#define ESC 27 // Escape (ESC) bottom in keyboard
#define N 110 // (N) Letter bottom in keyboard
#define P 112 // (P) Letter bottom in keyboard
#define MAX_X 800 // max value in X direction
#define MAX_Y 600 // max value in Y direction
#define BK_COL WHITE // The background color for the Game ( White )
#define BALL_RADIUS 10 // The value of the Ball Radius = 10
#define BALL_COLOR BLACK // The background color for the Ball
#define PAD_HEIGHT 20 // The Height of the Pad (Thickness) ( in Y direction )
#define PAD_ELEV 50 // The ELEV of the Pad ( in X direction )
#define BRICK_WIDTH 75 // The Width of the Brick ( in X direction )
#define BRICK_THICK 20 // The Height (Thickness) of the Pad ( in Y direction )
#define BULLET_THK 8 // The Height (Thickness) of the Bullet ( in Y direction )
#define BULLET_HGT 15 // The Width of the Bullet ( in X direction )

using namespace std;

enum Direction { RT, LT//, UP, DN}; // enumeration of the directions


void gameover(); // declaration of the function

class Shape {
private: //Private members in Shape class
int xpos, ypos; //integer (X position and Y position)
int col; // integer represent the number of the selected color
public: //Public members in Shape class
Shape(int x,int y,int c): xpos(x), ypos(y), col(c){ } // Constructor
int getXpos() {return xpos;} // Function to get the value of X position
int getYpos() {return ypos;} // Function to get the value of Y position
void setXpos(int x) {xpos=x; } // Function to set the value of X position
void setYpos(int y) {ypos=y; } // Function to set the value of y position
int getCol(){return col;} // Function to get the color

Dx-Ball Documentation 6
void draw(){ // Function to draw the Shape
setfillstyle(SOLID_FILL,col);
setcolor(15);
drawFilledShape(); }
void erase(){ //function to erase (delete) the selected shape
setfillstyle(SOLID_FILL,BK_COL);
drawFilledShape(); }
virtual void drawFilledShape()=0; // An Abstract function to draw a Filled Shape
};

class Circle: public Shape { // Class Circle inherited from class Shape
private: // Private members in class Circle
int radius; // Integer radius of the Circle
public: // Public members in class Circle
Circle(int x, int y, int r, int c): Shape(x,y,c), radius(r){} // Constructor
void drawFilledShape() { // Inherited function from class Shape to draw a filled shape
setlinestyle(SOLID_LINE,0,0); // Line style and color
fillellipse(getXpos(),getYpos(),radius,radius); } // To draw a Circle
};

class Rect: public Shape{ // Class Rect (Rectangle) inherited from class Shape
protected: // Protected members of class Rect, members are accessible from members of their same class
//& friend, classes, and also from members of their derived classes
int width; // Integer the Width of the Rectangle
int height; // Integer the Height of the Rectangle
public: // Public members of class Rect
Rect(int x, int y,int w,int h, int c): Shape(x,y,c),width(w),height(h){} // Constructor
void drawFilledShape() { // Inherited Function from class Shape
bar(getXpos(),getYpos(),getXpos()+width,getYpos()+height); }
};

class Pad:public Rect { // Class Pad inherited from class Rect inherited from class Shape
private: // Private members in class Pad
bool laserActive; // Bool Variable --> it represent True OR False
public: // Public members in class Pad
Pad(int x, int y,int w,int h, int c):Rect(x,y,w,h,c){ //Constructor
laserActive=false; // Initial value of variable laserActive
draw(); } // Inherited function from class shape

Dx-Ball Documentation 7
void move(Direction dir){ // Function to move the pad in X direction (Left OR Right)
int cshift= 30; // Variable represent the value of the Pad's Shift
int nx; // Represents the next value of the X pos (Notice: The pad moves only in X direction)
switch(dir){ // Switch of the direction (enumeration)
case LT: // Case left
while ( getXpos() > 0)
{ nx=getXpos()-cshift; // Generate the value of the next X position's value
erase(); // To erase the old Pad
setXpos(nx); // To reset the X pos to the new value (next X position)
draw(); // To draw the new pad in the new position
break; }
break;
case RT: // Case Right
while ( getXpos() < 700)
{ nx=getXpos()+cshift; // Generate the value of the next X position's value
erase(); // To erase the old Pad
setXpos(nx); // To reset the X pos to the new value (next X position)
draw(); // To draw the new pad in the new position
break; }
break;
} }
void draw() // Draw function inherited from class Rect
{ Shape::draw(); // Draw function inherited from class Shape
if(laserActive)
{ Rect l(getXpos()-10,getYpos()-5,10,20,BLUE); // Initialize Rect l
l.draw(); // Draw Rect l
Rect r(getXpos()+100,getYpos()-5,10,20,BLUE); //Initialize Rect r
r.draw(); } } // Erase Rect r
void erase() // Erase function inherited from class Rect
{ Shape::erase(); // Erase function inherited from class Shape
if(laserActive)
{ Rect l(getXpos()-10,getYpos()-5,10,20,BLUE); //Initialize Rect l
l.erase(); // Draw Rect l
Rect r(getXpos()+100,getYpos()-5,10,20,BLUE); // Initialize Rect r
r.erase(); } } // Erase Rect r
void activateLaser() // Function to set the value of variable laserActive
{ laserActive=true; // Value of variable laserActive
this->draw(); }
bool isLaserActive() // Function return the value of laserActive (True OR False)
{ return laserActive; }
};

Dx-Ball Documentation 8
class Brick : public Rect { //Class Brick inherited from class Rect inherited from class Shape
private: // Private members of class Brick
bool active; // Variable active (True OR False)
public: // Public members of class Brick
Brick(int x,int y,int w,int h,int c): Rect(x,y,w,h,c) //Constructor
{ active=true; } // Variable active (True OR False)
void draw() // Function draw inherited from class Rect
{ Rect::draw();
rectangle(getXpos(),getYpos(),width,height); }
void erase(){ Shape::erase();
active=false; }
bool checkActive() // To check the state (True OR False)
{ if(active==true)
return true;
else
return false; }
};

class Ball : public Circle{ //Class Ball inherited from class Circle inherited from class Shape
private:
float m; // Slope of the line of the circles' centers
int c; // Constant in the equation ( Y = m*X + c) defining the slope
int ballDir; // Represents the ball's direction ( Left OR Right)
float ballShift; // The shift in ball's position
bool thruActive; // Variable represented by (True OR False)
public:
Ball(int x,int y, int r, int col, int slope ) // Constructor
: Circle(x,y,r,col), m(slope),ballDir(1),ballShift(4),thruActive(false)
{ c=y-m*x; // Value of integer c from equation y=mx+c
draw(); }
void move() // Function to move the ball
{ c=getYpos()-m*getXpos(); // Get the value of variable c as w got from the equation
erase();
setXpos(getXpos()+ballDir*ballShift); // To reset the value of X position
setYpos(m*getXpos()+c); // To reset the value of Y position
draw(); } // To draw using the new values of X and Y position
void activateThru() // To activate the feature of the 'Through Ball'
{ thruActive=true; }
void setDir(int x) // To reset the value of Ball's Direction
{ ballDir=x; }

Dx-Ball Documentation 9
int getDir() // To get the value of Ball's Direction
{ return ballDir; }
void invSlope() { m=-m; } // To inverse the slope of the ball
void setSlope(float x) {m=x; } // To set the value of the slope of the ball
void adjSlope(float x) // To adjust the value of slope
{ if(ballDir>0) // If the Ball comes from the Left
m=-x;
else
m=x; }
void setShft(float x) // To set the value of ball's shift
{ ballShift=x; }
bool isThruActive() // To check if the 'Through Ball' is active
{ return thruActive; }
};

class Bonus : public Circle{ // Class Bonus inherited from class Circle
private: // Private members of class Bonus
unsigned int shift;
bool active; // (True OR False)
public: // Public members of class Bonus
Bonus(int x,int y, int r , int c): Circle(x,y,r,c), active(true) // Constructor
{ shift=2; // Initial value of variable 'shift'
draw(); }
void move() // Move function
setYpos(getYpos()+shift); // To reset the Y position to the new value
draw(); }
bool activate(Pad* pad,Ball* ball) // To check (True OR False)
{ if (getCol()==RED) // When contact with 'RED Ball' it is --> 'GameOver' :(
{ gameover();
return true; }
if(getCol()==BLUE) // When contact with 'Blue Ball' ,Laser is activated
pad->activateLaser();
if(getCol()== LIGHTBLUE) // When contact with 'LightBlue Ball' , Through Ball is activated
ball->activateThru();
return false; }
void setActive(bool x)
{ active=x; }
bool isActive()
{ return active; }
};

Dx-Ball Documentation 10
class Bullet : public Rect{ // Class Bullet inherited from class Rect
private: // Private members of class Bullet
unsigned int shift;
bool active; // (True OR False)
public: // Public members of class Bullet
Bullet(int x): Rect(x,MAX_Y-PAD_ELEV-5-BULLET_HGT,BULLET_THK,BULLET_HGT,RED) // Constructor
, active(true)
{ shift=2; // Initial value of variable shift
draw(); }
void move() // Move function
{ erase();
setYpos(getYpos()-shift); // To reset the Y pos to the new value
draw(); }
bool isActive()
{ return active; }
void setActive(bool x)
{ active=x; }
};

class Game{ // Class Game(Depends on all previous classes and functions)


private: // Private members of class Game
Pad *pad; // Pointer to pad
Ball *ball; // Pointer to Ball
Brick *brick[9][8]; // Pointer to array of Bricks
Bonus** bonus; // Pointer to pointer to bonus
Bullet** bullet; // Pointer to pointer to bullet
int LevelNum; // Integer represent Level number
int count; // Integer represent counter
bool breakLoop; // Bool variable (True OR False)
bool firstRun; // Bool variable (True OR False)
void showCredits() // Function to show the credit
{ outtextxy(MAX_X-650,MAX_Y-460,"MISSION ACCOMPLISHED");
delay(300); // time delay = 300 m seconds
outtextxy(MAX_X-650,MAX_Y-440,"THANKS FOR PLAYING");
delay(300);
outtextxy(MAX_X-650,MAX_Y-400,"SPECIAL THANKS TO");
delay(300);
outtextxy(MAX_X-620,MAX_Y-380,"DR.CHERIF SALAMA");
delay(300);
outtextxy(MAX_X-650,MAX_Y-340,"CREDITS");

Dx-Ball Documentation 11
delay(300);
outtextxy(MAX_X-620,MAX_Y-300,"AHMED ABD EL SHAKOUR");
delay(300);
outtextxy(MAX_X-620,MAX_Y-280,"ZIZO");
delay(300);
outtextxy(MAX_X-620,MAX_Y-260,"SHIKO");
delay(300);
outtextxy(MAX_X-620,MAX_Y-240,"MAHMOUD SOLIMAN");
delay(300);
LevelNum++; // increase the level number
outtextxy(MAX_X-750,MAX_Y-180,"RESTART FROM THE BEGINNING");
outtextxy(MAX_X-620,MAX_Y-160,"-N-");
outtextxy(MAX_X-480,MAX_Y-180,"QUIT THIS GAME");
outtextxy(MAX_X-440,MAX_Y-160,"-ESC-"); }
void generateBonus(Brick* brick ) // To generate the bonus
{if(rand()%16==0) // It'l be generated randomly
for(int k=0;k<30;k++)
if(bonus[k]==NULL)
{int j=rand()%7; // A random number from 0 to 6 will be generated to generate Bonus
if(j==0) // Death Ball
bonus[0]= new Bonus (brick->getXpos()+BRICK_WIDTH/2,brick->getYpos() +BRICK_THICK/
2,10,RED);
if(j==1) // Laser Ball
bonus[1]= new Bonus (brick->getXpos()+BRICK_WIDTH/2,brick->getYpos() +BRICK_THICK/
2,10,BLUE);
if(j==2) // Through Ball
bonus[2]= new Bonus (brick->getXpos()+BRICK_WIDTH/2,brick->getYpos() +BRICK_THICK/
2,10,LIGHTBLUE);
if(j==3) // Normal (Tricky) Ball
bonus[3]= new Bonus (brick->getXpos() +BRICK_WIDTH/2,brick->getYpos()+BRICK_THICK/
2,10,YELLOW);
if(j==4) // Normal (Tricky) Ball
bonus[4]= new Bonus (brick->getXpos()+BRICK_WIDTH/2,brick->getYpos() +BRICK_THICK/
2,10,LIGHTMAGENTA);
if(j==5) // Normal (Tricky) Ball
bonus[5]= new Bonus (brick->getXpos() +BRICK_WIDTH/2,brick->getYpos()+BRICK_THICK/
2,10,GREEN);
if(j==6) // Normal (Tricky) Ball
bonus[6]= new Bonus (brick->getXpos() +BRICK_WIDTH/2,brick->getYpos()+BRICK_THICK/
2,10,CYAN);

Dx-Ball Documentation 12
break; } }
void move() // Move function for class Game
{ int x,y,r; // Integers that will be used in this function only
x= BRICK_WIDTH + BALL_RADIUS ;
y= BRICK_THICK + BALL_RADIUS ;
r= BALL_RADIUS;
for(int i=0;i<9;i++){ // To check if there is a contact between Ball and Bricks
for(int j=0;j<8;j++){
if( ball->getXpos()>=brick[i][j]->getXpos()-BALL_RADIUS&&
ball->getXpos()<=brick[i][j]->getXpos()+BALL_RADIUS+BRICK_WIDTH&&
ball->getYpos()>=brick[i][j]->getYpos()-BALL_RADIUS&&
ball->getYpos()<=brick[i][j]->getYpos()+BALL_RADIUS+BRICK_THICK
&& brick[i][j]->checkActive() ) // If’s condition ( contact )
{ if(ball->getDir()<0&&ball->getXpos()>=brick[i][j]->getXpos()+BRICK_WIDTH){ // if contact from the Right
if(!ball->isThruActive())// If the 'Throgth Ball' feature is active
{ ball->setDir(1);
ball->invSlope(); }
brick[i][j]->erase(); // If the 'Through Ball' feature isn't active
generateBonus(brick[i][j]); }
else if(ball->getDir()>0&&ball->getXpos()<=brick[i][j]->getXpos()){ // if contact from the Left
if(!ball->isThruActive()) // If the through ball feature is active
{ ball->setDir(-1);
ball->invSlope(); }
brick[i][j]->erase(); // If the through ball feature isn't active
generateBonus(brick[i][j]); }
else{ // If contact from Up OR Down
if(!ball->isThruActive()) // If the through ball feature is active
ball->invSlope();
brick[i][j]->erase(); // If the 'Through Ball' feature isn't active
generateBonus(brick[i][j]);
}}
}}
// The next conditions will be to check contact between ball screen limits
if(ball->getXpos()>=MAX_X - BALL_RADIUS) // If contact to the Right Limit
{ ball->setDir(-1);
ball->invSlope();}
if(ball->getYpos() <= BALL_RADIUS) // If contact to the Upper Limit
{ ball->invSlope();
ball->erase();
ball->setYpos(BALL_RADIUS); }
// If contact to the Pad

Dx-Ball Documentation 13

if((ball->getYpos()>= MAX_Y - BALL_RADIUS - PAD_ELEV-2)&&(ball->getYpos()<=MAX_Y-PAD_ELEV+15))
// The PAD.It like we divide it into six parts like --> ---,---,---,---,---,---
{ if(((ball->getXpos() >= pad->getXpos()-BALL_RADIUS)&& (ball->getXpos() < (pad-
>getXpos()+100+BALL_RADIUS)))) // We work in this Part ===,---,---,---,---,--- from -20 to 0
if((ball->getXpos()-pad->getXpos()-BALL_RADIUS)<=20) // the ball contact the pad in left corner
{ ball->setShft(5);
ball->setDir(-1);
ball->setSlope(0.6); }
// We work in this Part ---,===,---,---,---,--- from 0 to 20
else if(((ball->getXpos()-pad->getXpos())>20)&&((ball->getXpos()-pad->getXpos())<=40))
{ ball->setShft(4);
ball->setDir(-1);
ball->setSlope(1); }
// We work in this Part ---,---,===,===,---,--- from 20 to 60
else if(((ball->getXpos()-pad->getXpos())>40)&&((ball->getXpos()-pad->getXpos())<=80))
{ ball->setShft(2);
ball->adjSlope(3); }
// We work in this Part ---,---,---,---,===,--- from 60 to 80
else if (((ball->getXpos()-pad-> getXpos())>80)&&((ball->getXpos()-pad->getXpos()) <=
100 ))
{ ball->setShft(4);
ball->setDir(1);
ball->setSlope(-1); }
// We work in this Part ---,---,---,---,---,=== from 80 to 100
else
{ ball->setShft(5);
ball->setDir(1);
ball->setSlope(-0.6); } } }
if(ball->getYpos()>=MAX_Y-PAD_ELEV+15) // If the ball passed the Pad, Game Over
{ gameover();
breakLoop=true; }
if(ball->getXpos() <= 0 + BALL_RADIUS) // If contact to the Right limit
{ ball->setDir(1);
ball->invSlope(); }
ball->move(); // We call the move function from class Ball
// This is the motion of the bonus
for(int k=0;k<30;k++)
if(bonus[k]!=NULL)
if(bonus[k]->isActive()){

Dx-Ball Documentation 14
bonus[k]->move();
for(int i=0;i<9;i++)
for(int j=0;j<8;j++)
if(x >= (bonus[k]->getXpos()-brick[i][j]->getXpos())&&
(bonus[k]->getXpos()-brick[i][j]->getXpos()) >= -(BALL_RADIUS) &&
y+3 >= (bonus[k]-> getYpos()-brick[i][j]-> getYpos())&&(bonus[k]-
>getYpos()-brick[i][j]-> getYpos())>= -(BALL_RADIUS) && brick[i][j]->checkActive())
brick[i][j]->draw();
if((bonus[k]->getYpos()>= MAX_Y - BALL_RADIUS - PAD_ELEV-
2)&&(bonus[k]->getYpos()<=MAX_Y-PAD_ELEV+15))
{ if(((bonus[k]->getXpos() >= pad->getXpos()-BALL_RADIUS)&&
(bonus[k]->getXpos() < (pad->getXpos()+100+BALL_RADIUS))))
{ breakLoop = bonus[k]->activate(pad,ball);
bonus[k]->erase();
bonus[k]->setActive(false); } } }
// This is the motion of the bullets
for(int k=0;k<30;k++)
if(bullet[k]!=NULL)
if(bullet[k]->isActive())
{ bullet[k]->move();
if(bullet[k]->getYpos()<=10)
{bullet[k]->setActive(false);
bullet[k]->erase(); }
for(int i=0;i<9;i++)
for(int j=0;j<8;j++) if( brick[i][j]->getXpos()<=bullet[k]-> getXpos()&&bullet[k]->getXpos()-brick[i][j]->
getXpos()<=(BRICK_WIDTH-BULLET_THK) && bullet[k]->getYpos()<=(brick[i][j]-> getYpos()+BRICK_THICK)&& brick[i][j]-
>checkActive())
{brick[i][j]->erase();
generateBonus(brick[i][j]);
bullet[k]->setActive(false);
bullet[k]->erase(); } } }
void levelComplete() // When the Level is Complete
{ LevelNum++;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,800,600);
settextstyle(3,0,1);
setcolor(10);
if((LevelNum%4)<4) // If there is more Levels
{ outtextxy(MAX_X-650,MAX_Y-460,"Level Complete");
delay(300);

Dx-Ball Documentation 15
outtextxy(MAX_X-650,MAX_Y-180,"Next Level");
outtextxy(MAX_X-620,MAX_Y-160,"-N-");
outtextxy(MAX_X-480,MAX_Y-180,"Exit Game");
outtextxy(MAX_X-440,MAX_Y-160,"-ESC-");
}
else // If the Levels are Complete
{ showCredits(); }
char c;
while(1)
{ if(kbhit()) {c=getch();
if(c==ESC) { // Hit ESC to Exit the Game
delay(100);
exit(0); }
else if (c== N) // Hit -N- to start the Game OR Go to the new Level
{ if((LevelNum%4)==0)
LevelNum=0;
setfillstyle(SOLID_FILL,BLACK);
bar(0,0,800,600);
outtextxy(MAX_X-650,MAX_Y-460,"LOADING ...");
delay(2000);
breakLoop=true;
setcolor(15);
break; } } } }
public: // Public members of class Game
Game()
{ count = 0; // Initial value of the integer count
LevelNum=0; // Initial value of the integer LevelNum
firstRun=true;
srand((unsigned)time(NULL));
initwindow(MAX_X,MAX_Y,"Dx-Ball"); } // To draw a window with the written name
void showEntrance() { // The Main Menu Screen
settextstyle(3,0,10);
setcolor(10);
outtextxy(MAX_X-550,MAX_Y-560,"DX - BALL");
delay(300); // Time delay = 300 mseconds
settextstyle(3,0,1);
setcolor(10);
outtextxy(MAX_X-480,MAX_Y-380,"COLORED BALLS");
delay(300);
setcolor(RED);

Dx-Ball Documentation 16
outtextxy(MAX_X-465,MAX_Y-340,"DEATH BALL");
delay(300);
Circle c1(MAX_X-420,MAX_Y-310,10,RED);
c1.draw();
delay(300);
setcolor(BLUE);
outtextxy(MAX_X-465,MAX_Y-300,"LASER BALL");
delay(300);
Circle c2(MAX_X-420,MAX_Y-270,10,BLUE);
c2.draw();
delay(300);
setcolor(9);
outtextxy(MAX_X-475,MAX_Y-260,"THROUGH BALL");
delay(300);
Circle c3(MAX_X-420,MAX_Y-230,10,LIGHTBLUE);
c3.draw();
delay(300);
setcolor(10);
outtextxy(MAX_X-500,MAX_Y-180,"NEW GAME");
delay(300);
outtextxy(MAX_X-430,MAX_Y-160,"-N-");
delay(300);
outtextxy(MAX_X-500,MAX_Y-140,"PAUSE");
delay(300);
outtextxy(MAX_X-430,MAX_Y-120,"-P-");
delay(300);
outtextxy(MAX_X-500,MAX_Y-100,"QUIT");
delay(300);
outtextxy(MAX_X-430,MAX_Y-80,"-P + ESC-"); }
void start() // To start the game
{ while(firstRun)
{ if(getch()== 'n')
firstRun=false; }
drawLevel(LevelNum); // To draw the given level by it's number
breakLoop=false;
stickyBall();
char c;
while(1) // Used to continually check if there is any activated features Or if the level is complete
{ bool levelComp=true;
for(int i=0;i<9;i++) // When all bricks are deactivated . The Level is complete

Dx-Ball Documentation 17
for(int j=0;j<8;j++)
if((brick[i][j]->checkActive())) { levelComp=false; }
if(levelComp) { levelComplete(); }
move();
for(int i=0;i<30;i++) // To check the activity of the Bonus
{ if(bonus[i]!=0)
if(!bonus[i]->isActive())
{ delete bonus[i];
bonus[i]=NULL; }
else
bonus[i]->move(); // To move the bonus
if(bullet[i]!=0) // To check the activity of the Bullets
{ if(!bullet[i]->isActive())
{delete bullet[i];
bullet[i]=NULL;}
else
bullet[i]->move(); } }
if (breakLoop) { break; }
delay(25);
if(kbhit())
{ c = getch();
if(c==P) // When the user press ESC he is out the game
{ while(1) {
char x=getch();
if(x==ESC){ exit(0); }
else{ break; } } }
if(c==' ') { // When the user press space the bullets are ON
if(pad->isLaserActive())
{ for(int i=0;i<30;i++)
if(bullet[i]==NULL) {
bullet[i]=new Bullet(pad->getXpos()-8);
break; }
for(int i=0;i<30;i++)
if(bullet[i]==NULL)
{ bullet[i]=new Bullet(pad->getXpos()+100);
break; } } }
if(c==0){
c = getch();
switch(c){ // Switch case for the directions

Dx-Ball Documentation 18
case RIGHT_ARROW:
pad->move(RT);
break;
case LEFT_ARROW:
pad->move(LT);
break; } } } }
for(int i=0;i<30;i++)
{ if(bonus[i]!=0)
{delete bonus[i];
bonus[i]=0; }
if(bullet[i]!=0)
{ delete bullet[i];
bullet[i]=0; } }
this->start(); }
void stickyBall() // To held the ball steady on the pad
{ while(1)
{ char c;
if(kbhit())
{ c = getch();
if(c==' ') { break; }
if(c==0){ c = getch();
switch(c){
case RIGHT_ARROW:
ball->erase();
pad->move(RT);
ball->setXpos(pad->getXpos()+50);
ball->draw();
break;
case LEFT_ARROW:
ball->erase();
pad->move(LT);
ball->setXpos(pad->getXpos()+50);
ball->draw();
break; } } } } }
void drawLevel(int level) // To draw the different Levels
{ setlinestyle(SOLID_FILL,0,5);
setfillstyle(SOLID_FILL,BK_COL);
bar(0,0,MAX_X,MAX_Y);
ball = new Ball(MAX_X/2,MAX_Y-PAD_ELEV-BALL_RADIUS-10,BALL_RADIUS,BALL_COLOR,-1);

Dx-Ball Documentation 19

// Drawing the Levels
for(int i=0;i<9;i++){ for(int j=0;j<8;j++)
{ brick[i][j] = new Brick(85+(80*j),(i*23)+60,BRICK_WIDTH,BRICK_THICK,i+1);
brick[i][j]->draw(); } }
if (level==1){ // Unused Bricks Level 1
brick[0][0]->erase();
brick[1][0]->erase();
brick[5][0]->erase();
brick[6][0]->erase();
brick[0][7]->erase();
brick[1][7]->erase();
brick[5][7]->erase();
brick[6][7]->erase();
brick[8][3]->erase();
brick[8][4]->erase();
brick[3][2]->erase();
brick[3][5]->erase();
brick[0][1]->erase();
brick[7][1]->erase();
brick[8][1]->erase();
brick[0][6]->erase();
brick[7][6]->erase();
brick[8][6]->erase();
brick[8][2]->erase();
brick[8][5]->erase();
brick[7][2]->erase();
brick[7][3]->erase();
brick[7][4]->erase();
brick[7][5]->erase();
brick[6][1]->erase();
brick[6][6]->erase();}
else if (level==2){ // Unused Bricks in level 2
brick[1][0]->erase();
brick[3][0]->erase();
brick[5][0]->erase();
brick[7][0]->erase();
brick[0][1]->erase();
brick[2][1]->erase();
brick[4][1]->erase();
brick[8][1]->erase();

Dx-Ball Documentation 20

brick[6][1]->erase();
brick[1][2]->erase();
brick[3][2]->erase();
brick[5][2]->erase();
brick[7][2]->erase();
brick[0][3]->erase();
brick[2][3]->erase();
brick[6][3]->erase();
brick[4][3]->erase();
brick[8][3]->erase();
brick[1][4]->erase();
brick[3][4]->erase();
brick[5][4]->erase();
brick[7][4]->erase();
brick[1][6]->erase();
brick[3][6]->erase();
brick[5][6]->erase();
brick[7][6]->erase();
brick[0][5]->erase();
brick[2][5]->erase();
brick[6][5]->erase();
brick[4][5]->erase();
brick[8][5]->erase();
brick[0][7]->erase();
brick[2][7]->erase();
brick[6][7]->erase();
brick[4][7]->erase();
brick[8][7]->erase();}
else if (level==3){ // Unused Bricks in Level 3
brick[0][0]->erase();
brick[1][0]->erase();
brick[2][0]->erase();
brick[3][0]->erase();
brick[4][0]->erase();
brick[5][0]->erase();
brick[6][0]->erase();
brick[7][0]->erase();
brick[8][0]->erase();
brick[0][2]->erase();
brick[1][2]->erase();

Dx-Ball Documentation 21
brick[2][2]->erase();
brick[3][2]->erase();
brick[4][2]->erase();
brick[5][2]->erase();
brick[6][2]->erase();
brick[7][2]->erase();
brick[8][2]->erase();
brick[0][4]->erase();
brick[1][4]->erase();
brick[2][4]->erase();
brick[3][4]->erase();
brick[4][4]->erase();
brick[5][4]->erase();
brick[6][4]->erase();
brick[7][4]->erase();
brick[8][4]->erase();
brick[0][6]->erase();
brick[1][6]->erase();
brick[2][6]->erase();
brick[3][6]->erase();
brick[4][6]->erase();
brick[5][6]->erase();
brick[6][6]->erase();
brick[7][6]->erase();
brick[8][6]->erase(); }
pad = new Pad(MAX_X/2-50,MAX_Y-PAD_ELEV,100,PAD_HEIGHT,RED);
bonus = new Bonus*[30];
bullet = new Bullet*[30];
for(int i=0;i<30;i++)
{ bonus[i]=NULL;
bullet[i]=NULL; } }
};
void gameover() // GameOver function
{setfillstyle(SOLID_FILL,BLACK);
setbkcolor(BLACK);
bar(0,0,800,600);
settextstyle(3,0,1);
setcolor(10);
outtextxy(MAX_X-650,MAX_Y-460,"MISSION FAILED");
delay(300);

Dx-Ball Documentation 22
outtextxy(MAX_X-650,MAX_Y-180,"TRY AGAIN");
outtextxy(MAX_X-620,MAX_Y-160,"-N-");
outtextxy(MAX_X-480,MAX_Y-180,"QUIT THIS GAME");
outtextxy(MAX_X-440,MAX_Y-160,"-ESC-");
char c;
while(1)
{ c=getch();
if(c==ESC){ delay(100);
exit(0); }
else if (c== N){ setfillstyle(SOLID_FILL,BLACK);
bar(0,0,800,600);
outtextxy(MAX_X-650,MAX_Y-460,"LOADING ...");
delay(2000);
setcolor(15);
break; } }
}

void main() // Main function


{ HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,10);
cout<<"SPECIAL THANKS TO DR.CHERIF SALAMA \n"<<endl ;
cout<<"\n" ;
cout<<"CREDITS \n" ;
cout<<"\n" ;
cout<<"ABD EL SHAKOUR \n" ;
cout<<"ZIZO \n" ;
cout<<"SHIKO \n" ;
cout<<"MAHMOUD SOLIMAN \n"<< endl ;
cout<<"\n" ;
cout<<">>: \n" ;
Game game;
game.showEntrance();
game.start(); }

Dx-Ball Documentation 23
Contact Information

For more information

Please Contact Us at:

Ahmed Abdelshakour Allam

ahmabdabd@hotmail.com

Ahmed Abdelaziz Mohamed

ahmedoz_89@hotmail.com

Sherif Mostafa Eltoukhi

sherif_el_toukhi@live.com

Mahmoud Soliman Aglan

mahmoud.soliman@aybasu.com

Thank you !

Developers Team

Dx-Ball Documentation 24

Vous aimerez peut-être aussi