#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<mouse.h>
int x,y,a,b,area,px,py,stat,bx=20,by=200,bxspeed=2,byspeed=2,scr=0;
static int sq[15][15];
char *paddal,*ball,dir[3]="br",score[4]="ss";
void first_page()
{
int x_center = 320, y_center = 240, rad = 220;
int z,k,x[10],y[10];
int xi,yi,h;
setcolor(4);
for( xi=30;xi>4;xi--)
{
sound(xi*20);
settextstyle(GOTHIC_FONT,HORIZ_DIR,xi);
outtextxy(xi,220,"Gaming begins here......");
delay(320);
cleardevice();
}
setcolor(10);
for (z=0;z<10;z++)
{
x[z]=x_center+rad*cos(36*z*3.14159/180);
y[z]=y_center+rad*sin(36*z*3.14159/180);
}
for (z=0;z<10;z++)
for (k=0;k<10;k++)
{
sound(k*200);
delay(50);
line(x[z],y[z],x[k],y[k]);
nosound();
}
for( h=0;h<500;h++)
{
sound(h*9);
setfillstyle( random(12),random(15) );
bar3d(random(640),random(480),random(640),random(480),random(30),
random(18));
}
// op_graph++;
nosound();
}
/*
void menu(int a,int b,int c,int d,int e)
{
setcolor(a);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,7);
outtextxy(22,100,"1. BRICKS");
setcolor(b);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,7);
outtextxy(22,200,"2. PAIRS II");
setcolor(c);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(15,300,"3. HELP");
setcolor(d);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(15,350,"4. CREDITS");
setcolor(e);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(15,400,"5. EXIT");
}
*/
int screen()
{
int i, j, lx = 0, ly = 0, ch ;
int gd=DETECT,gm;
rectangle(1,1,600,195);
setbkcolor(4);
/* set the textstyle for displaying instruction */
settextstyle ( DEFAULT_FONT, HORIZ_DIR, 0 ) ;
outtextxy ( 150, 55, " Instructions " ) ;
settextstyle (4, HORIZ_DIR, 5 );
outtextxy ( 130, 0, " B R I C K S" ) ;
settextstyle ( DEFAULT_FONT, HORIZ_DIR, 0 ) ;
outtextxy ( 30, 68, "Use mouse to move the paddle" ) ; // can also
outtextxy ( 30, 88, "If you don't collect the ball on the paddle, youlose the ball." ) ;
outtextxy ( 30, 108, "On loosing a ball you loose 10 points." ) ;
outtextxy ( 30, 128, "On taking a brick you gain 10 points." ) ;
settextstyle(7, HORIZ_DIR, 3);
outtextxy ( 100, 148, "Press any key to continue ..." ) ;
//bell ( 3 ) ; /* ring music */
fflush ( stdin ) ;
// if ( getch() == 0 )
// getch() ;
closegraph();
initgraph ( &gd, &gm, "c:\\tc\\bgi" ) ;
rectangle(2,2,620,195);
setbkcolor(4);
/* display the main menu */
while ( 1 )
{
settextstyle(4,HORIZ_DIR,5);
outtextxy ( 60, 8, "Options Available:" ) ;
outtextxy ( 150, 55, "Play ( P )" ) ;
outtextxy ( 150, 125, "Exit ( E )" ) ;
ch = 0 ;
/* continue untill you select the correct choice */
while ( ! ( ch == 'E' || ch == 'P' ) )
{
fflush ( stdin ) ;
/* if a special key is hit, flush the keyboard buffer */
if ( ( ch = getch() ) == 0 )
getch() ;
else
ch = toupper ( ch ) ; /* store the uppercase of the choice made*/
}
if ( ch == 'P' )
break ;
if (ch == 'E')
exit ( 0 ) ;
}
// setviewport ( 1, 125 - 12, MaxX - 1, MaxY - 1, 1 ) ;
// clearviewport() ;
closegraph();
initgraph ( &gd, &gm, "c:\\tc\\bgi" ) ;
rectangle(2,2,620,195);
setbkcolor(4);
/* display menu for the diffrent levels */
settextstyle(7,HORIZ_DIR,3);
outtextxy ( 60, 8, "Select the level for play:" ) ;
outtextxy ( 150,50, "Slow ( S )" ) ;
outtextxy ( 150, 100, "Medium ( M )" ) ;
outtextxy ( 150, 150, "Fast ( F )" ) ;
/* accept user's choice */
fflush ( stdin ) ;
if ( ( ch = getch() ) == 0 )
getch() ;
clearviewport() ;
/* return the choice selected by the user */
return ( ch ) ;
}
void main()
{
char*img1,*img2;
int gd=DETECT,gm,level,speed;
initgraph(&gd,&gm,"c:\\tc\\bgi");
x=getmaxx()/2,y=getmaxy()/2;
first_page();
level = screen() ;
/* assign the speed to ball as per the level chosen */
switch ( level )
{
case 'M' :
case 'm' :
speed = 10 ;
break ;
case 'F' :
case 'f' :
speed = 3 ;
}
backfrm();
splace_form();
initmouse();
while(1)
{
getmousepos(&stat ,&px ,&py);
delay(11);
if(stat==1)
break;
}
mainfrm();
backfrm();
dpaddal();
backfrm();
dball();
backfrm();
lavel(2);
printlevel();
restrictmouseptr(16,500,540,500);
while(!kbhit())
{
delay(10);
movepaddal();
moveball();
}
getch();
}
//---------------------move ball---------------///
moveball()
{
setfillstyle(SOLID_FILL,1);
bar(bx-2,by-2,bx+12,by+12);
putimage(bx,by,ball,COPY_PUT);
balldir();
if(!strcmp(dir,"bl")) bx-=bxspeed,by+=byspeed;
if(!strcmp(dir,"br")) bx+=bxspeed,by+=byspeed;
if(!strcmp(dir,"tl")) bx-=bxspeed,by-=byspeed;
if(!strcmp(dir,"tr")) bx+=bxspeed,by-=byspeed;
}
//-----------------------ball direction---------------//
balldir()
{
if(!strcmp(dir,"bl") && by>440) btp("tl");
if(!strcmp(dir,"br") && by>440) btp("tr");
if(!strcmp(dir,"tl") && by<122&&sq[(by-55)/15][(bx-16)/50]==0)
bts("bl");
if(!strcmp(dir,"tr") && by<122&&sq[(by-55)/15][(bx-16)/50]==0)
bts("br");
if(!strcmp(dir,"bl") && by<122&&sq[(by-55)/15][(bx-16)/50]==0)
bts("tl");
if(!strcmp(dir,"br") && by<122&&sq[(by-55)/15][(bx-16)/50]==0)
bts("tr");
if(!strcmp(dir,"tr") && by<40) strcpy(dir,"br"),sndplay(500);
if(!strcmp(dir,"tl") && by<40) strcpy(dir,"bl"),sndplay(500);
if(!strcmp(dir,"bl") && bx<20) strcpy(dir,"br"),sndplay(500);
if(!strcmp(dir,"tr") && bx>600) strcpy(dir,"tl"),sndplay(500);
if(!strcmp(dir,"tl") && bx<20) strcpy(dir,"tr"),sndplay(500);
if(!strcmp(dir,"br") && bx>600) strcpy(dir,"bl"),sndplay(500);
}
//-------------------------move paddal---------------///
movepaddal()
{
setfillstyle(SOLID_FILL,1);
bar(16,450,612,460);
getmousepos(&stat ,&px ,&py);
putimage(px,450,paddal,COPY_PUT);
}
//-----------------paddal--------------------//
dpaddal()
{
int area;
setfillstyle(SOLID_FILL,15);
fillellipse(x,y,35,4);
area=imagesize(x-35,y-4,x+35,y+4); // find area of image
paddal=malloc(area);
getimage(x-35,y-4,x+35,y+4,paddal); //get image in *paddal
}
//------------------ball------------------------//
dball()
{
int area;
setfillstyle(SOLID_FILL,4);
fillellipse(x,y,5,5);
area=imagesize(x-5,y-5,x+5,y+5); // find area of image
ball=malloc(area);
getimage(x-5,y-5,x+5,y+5,ball); //get image in *ball
}
//-----------------------print squar--------------//
squar(int a,int b ,int norm)
{
setfillstyle(SOLID_FILL,13);
if(b%2)
setfillstyle(SOLID_FILL,3);
if(norm==0)
setfillstyle(SOLID_FILL,1);
bar(b*50+16,a*15+55,b*50+63,a*15+54+13);
setfillstyle(SOLID_FILL,1);
bar(100,16,140,30);
setcolor(15);
settextstyle(2,0,6);
outtextxy(20,15,"Score -");
itoa(scr,score,10);
outtextxy(100,15,score);
}
//------------------------backfrm-------------------//
backfrm()
{
setfillstyle(SOLID_FILL,1);
bar(15,15,615,465);
button(0,0,15,480,1);
button(615,0,630,480,1);
button(0,0,630,15,1);
button(0,465,630,480,1);
}
//---------------SPLACE FORM---------------------------//
splace_form()
{
setcolor(4);
settextstyle(4,0,6);
outtextxy(x-145,y-200, " GAME");
outtextxy(x-145,y-50, "DX==BALL");
setcolor(2);
outtextxy(x-145,y-150, "--------");
settextstyle(1,0,1);
}
//--------------------------BUTTON-------------------------//
button(int xl,int yt,int xr,int yb, int status)
{
setfillstyle(SOLID_FILL, LIGHTGRAY);
bar(xl, yt, xr, yb);
if (status)
{
setcolor(WHITE);
line(xl,yt,xl,yb-1);
line(xl,yt,xr-1,yt);
setcolor(DARKGRAY);
line(xr,yb,xl,yb);
line(x