Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

BALLCATCHER c++ GAME

Ballcatcher is a c++ game in which you have to move a basket to catch the falling balls.I developed it as a part of my school project.Feel free to email me at davidchristiek@gmail.com regarding this.

You can download it from here
https://drive.google.com/file/d/0B3kz1y1YuVuJSTNmQ1V4cE54NEE/view?usp=sharing

`#include<iostream.h>

include<conio.h>

include<graphics.h>

include<stdlib.h>

include<dos.h>

int speed=1;
int movementspeed=1;
int life=3,score=0;
char scor[10];

void credits()
{
setcolor(WHITE);
setbkcolor(WHITE);
setfillstyle(1,BLUE);
bar(200,200,500,300);
settextstyle(3,0,6);
outtextxy(210,200,"W");
delay(500);
outtextxy(250,200,"O");
delay(500);
outtextxy(280,200,"L");
delay(500);
outtextxy(310,200,"F");
delay(500);
outtextxy(340,200,"P");
delay(500);
outtextxy(370,200,"A");
delay(500);
outtextxy(400,200,"C");
delay(500);
outtextxy(430,200,"K");
delay(1000);
settextstyle(5,0,4);
setcolor(YELLOW);
outtextxy(240,240,"Innovations");
setcolor(RED);
rectangle(200,200,500,300);
getch();
cleardevice();
}
void instructions()
{
setbkcolor(RED);
setcolor(YELLOW);
settextstyle(6,0,6);
outtextxy(200,20,"INSTRUCTIONS");
settextstyle(1,0,3);
outtextxy(20,100,"1.Catch as many balls as possible");
outtextxy(20,200,"2.Don't lose more than 3 balls");
outtextxy(20,300,"3.Press space to exit");
outtextxy(20,400,"4.Use A,D to move");
outtextxy(100,450,"PRESS ANY KEY TO PLAY");
getche();
cleardevice();
}
void gameover()
{
setcolor(RED);
settextstyle(4,0,6);
outtextxy(250,200,"Game Over");
delay(2000);
cleardevice();
setbkcolor(YELLOW);
settextstyle(5,0,6);
outtextxy(100,40,"Thank you for playing");
outtextxy(100,100,"You have scored:");
outtextxy(100,175,scor);
outtextxy(100,250,"Press space to exit....");
char ch='w';
while(ch!=' ')
ch=getch();

}
void main()
{
clrscr();
randomize();
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\tc\BGI");
settextstyle(3,0,4);
char key='y';
//basket
setfillstyle(1,RED);
setbkcolor(LIGHTBLUE);
bar(0,0,60,20);
bar(15,20,45,30);
bar(22,30,36,35);
unsigned int size;
struct
{
void *basket;
int x,y;
}basket;
size=imagesize(0,0,60,35);
basket.basket=malloc(size);
getimage(0,0,60,35,basket.basket);
cleardevice();
//ball
setcolor(RED);
setbkcolor(LIGHTBLUE);
setfillstyle(1,YELLOW);
circle(15,15,15);
floodfill(15,15,RED);
struct
{
void *ball;
int x,y;
}ball;
size=imagesize(0,0,30,30);
ball.ball=malloc(size);
getimage(0,0,30,30,ball.ball);
cleardevice();
//Heart
setbkcolor(LIGHTBLUE);
cout<<(char)3;
void *heart;
size=imagesize(0,0,12,12);
heart=malloc(size);
getimage(0,0,12,12,heart);

cleardevice();
credits();
instructions();
ball.x=random(450);
ball.y=60;
basket.x=225;
basket.y=430;
setcolor(RED);
line(450,0,450,480);
setfillstyle(9,YELLOW);
floodfill(500,50,RED);
setbkcolor(LIGHTBLUE);
setfillstyle(9,YELLOW);
setcolor(YELLOW);
line(500,0,500,480);
floodfill(550,20,YELLOW);
setcolor(GREEN);
line(0,50,640,50);
setfillstyle(9,GREEN);
floodfill(25,25,GREEN);

setcolor(RED);
outtextxy(200,-2,"BALL CATCHER");
setcolor(RED);

outtextxy(520,60,"Life");
setfillstyle(1,YELLOW);
bar(520,100,580,110);
setcolor(RED);
outtextxy(520,150,"SCORE");
setfillstyle(1,YELLOW);
bar(520,200,600,250);
settextstyle(3,0,2);
outtextxy(520,380,"CREATED BY");
setcolor(YELLOW);
setfillstyle(1,BLUE);
bar(520,420,620,450);
setcolor(RED);
settextstyle(3,0,2);
setcolor(WHITE);
outtextxy(520,420,"WOLFPACK");
for(int lhpos=520;lhpos<520+20*3;lhpos+=20)
putimage(lhpos,100,heart,COPY_PUT);
lhpos-=20;
for(int i=0;i<2000;i++)
{
putpixel(random(450),50+random(430),YELLOW);
delay(1);
}
while(key!=' ')
{
if(life<0)
{
gameover();
break;
}
putimage(basket.x,basket.y,basket.basket,COPY_PUT);
putimage(ball.x,ball.y,ball.ball,XOR_PUT);
itoa(score,scor,10);
settextstyle(4,0,4);
setcolor(RED);
outtextxy(540,210,scor);
if(abs(ball.x-basket.x)<30&&abs(ball.y-basket.y)<30)
{
setcolor(YELLOW);
outtextxy(540,210,scor);
score+=10;
putimage(ball.x,ball.y,ball.ball,XOR_PUT);
ball.x=random(430);
ball.y=60;
putimage(basket.x,basket.y,basket.basket,XOR_PUT);
continue;
}
if(abs(ball.y-460)<30)
{
life--;
putimage(lhpos,100,heart,XOR_PUT);
lhpos-=20;
putimage(ball.x,ball.y,ball.ball,XOR_PUT);
ball.x=random(430);
ball.y=60;
putimage(basket.x,basket.y,basket.basket,XOR_PUT);
continue;
}

delay(speed);
putimage(ball.x,ball.y,ball.ball,XOR_PUT);
ball.y++;
if(kbhit())
{
key=getch();
putimage(basket.x,basket.y,basket.basket,XOR_PUT);
switch(key)
{
case 'A':
case 'a':

if(basket.x>20)
{
 basket.x-=movementspeed*20;
}
break;
case 'D':
case 'd':
if(basket.x<380)
{
 basket.x+=movementspeed*20;
}
break;

}

}
}
getch();
}`

Tagged:
Sign In or Register to comment.