Phrozen
05-03-03, 05:32 AM
Ctrl V says:
#include"process.h"
#include"dos.h"
#include"stdlib.h"
#include"graphics.h"
#include"stdio.h"
#define NULL 0
#define YES 1
#define NO 0
int maxx,maxy,midx,midy;
int bri[3][16];
char str[20];
main()
{
union REGS ii,oo;
int ballx,bally,paddlex,paddley,dx=1,dy=-1,oldx,oldy;
int gm=VGAHI, gd=VGA, playerlevel;
int i,flag=0,speed=25,welldone=NO,score=0,chance=4,are a;
int layer[3]={25,50,75},limit=75,currentlayer=2;
char *p1,*p2;
initgraph(&gd,&gm,"d:\\tcc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
playerlevel=mainscreen();
switch(playerlevel)
{
case 'A':
case 'a':
speed=15;
break;
case 'E':
case 'e':
speed=5;
}
rectangle(0,0,maxx,maxy-26);
bricks();
setfillstyle(SOLID_FILL,YELLOW);
rectangle(midx-25,maxy-50,midx+25,maxy-20-9);
floodfill(midx,maxy-33,WHITE);
setfillstyle(SOLID_FILL,LIGHTBLUE);
circle(midx,maxy-50-13,12);
floodfill(midx,maxy-50-15,WHITE);
area=imagesize(midx-12,maxy-50-12-12-1,midx+12,maxy-50-1);
p1=malloc(area);
area=imagesize(midx-25,maxy-50,midx+25,maxy-20-9);
p2=malloc(area);
if(p1==NULL||p2==NULL)
{
puts("Insufficient memory!?");
exit(1);
}
getimage(midx-12,maxy-50-12-12-1,midx+12,maxy-50-1,p1);
getimage(midx-25,maxy-50,midx+25,maxy-20-9,p2);
paddlex=midx-25;
paddley=maxy-50;
ballx=midx-12;
bally=maxy-50-12-12-1;
settextstyle(0,0,1);
outtextxy(300,470,"Balls remaining:");
for(i=0;i<3;i++)
{
circle(515+i*40,maxy-12,12);
floodfill(515+i*40,maxy-12,WHITE);
}
outtextxy(50,470,"Your Score:");
sprintf(str,"%4d",score);
outtextxy(140,470,str);
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(0,HORIZ_DIR,0);
while(1)
{
flag=0;
oldx=ballx;
oldy=bally;
ballx=ballx+(dx*3);
bally=bally+(dy*3);
if(bally>50)
{
limit=75;
currentlayer=2;
}
else
{
if(bally>25)
{
limit=50;
currentlayer=1;
}
else
{
limit=25;
currentlayer=0;
}
}
if(ballx<1)
{
music(5);
ballx=1;
dx=-dx;
}
if(ballx>(maxx-24-1))
{
music(5);
ballx=maxx-24-1;
dx=-dx;
}
if(bally<1)
{
music(5);
bally=1;
dy=-dy;
}
if(bally<=limit)
{
if(bri[currentlayer][(ballx+10)/40]==1)
{
for(i=1;i<=6;i++)
{
if(bri[currentlayer][(ballx+i+10)/40]==0)
{
ballx=ballx+i;
flag=1;
break;
}
if(bri[currentlayer][(ballx-i+10)/40]==0)
{
ballx=ballx-i;
flag=1;
break;
}
}
if(!flag)
{
if(bally<layer[currentlayer-1])
{
currentlayer--;
limit=layer[currentlayer];
}
/* put the image of the ball at the old coordinates */
putimage(oldx,oldy,p1,OR_PUT);
putimage(oldx,oldy,p1,XOR_PUT);
putimage(ballx,bally,p1,XOR_PUT);
delay(speed);
continue;
}
}
music(4);
erasebrick((ballx+10)/40,currentlayer);
if((ballx+10)/40>=15)
line(maxx,0,maxx,75);
if((ballx+10)/40==0)
line(0,0,0,75);
if(currentlayer==0)
line(0,0,maxx,0);
bri[currentlayer][(ballx+10)/40]=1;
bally=bally+1;
dy=-dy;
score+=5;
setviewport(150,470,180,479,1);
clearviewport();
setviewport(0,0,maxx,maxy,1);
sprintf(str,"%4d",score);
outtextxy(152,475,str);
if(welldone==NO)
welldone=YES;
else
{
settextstyle(7,0,4);
outtextxy(midx,midy,"Well done!");
music(1);
settextstyle(0,0,1);
}
}
if(bally>75&&welldone==YES)
{
setviewport(midx-40*2.5,midy-40/2,midx+40*2.5,midy+40/2,1);
clearviewport();
setviewport(0,0,maxx,maxy,1);
welldone=NO;
}
if(bally>maxy-12-12-50-1)
{
welldone=NO;
if(ballx<paddlex-20||ballx>paddlex+50)
{
while(bally<maxy)
{
putimage(oldx,oldy,p1,XOR_PUT);
putimage(ballx,bally,p1,XOR_PUT);
delay(speed);
oldx=ballx;
oldy=bally;
ballx=ballx+dx;
bally=bally+dy;
}
chance--;
score-=20;
setviewport(150,470,180,479,1);
clearviewport();
setviewport(0,0,maxx,maxy,1);
sprintf(str,"%4d",score);
outtextxy(152,475,str);
music(2);
if(chance)
{
setcolor(BLACK);
putimage(515+(chance-1)*40-12,maxy-19-5,p1,XOR_PUT);
}
if(!chance)
{
settextstyle(7,0,4);
outtextxy(midx,midy,"I warned you ! try again");
music(3);
getch();
closegraph();
restorecrtmode();
exit(0);
}
}
music(5);
bally=maxy-12-12-50-1;
dy=-dy;
}
putimage(oldx,oldy,p1,OR_PUT);
putimage(oldx,oldy,p1,XOR_PUT);
putimage(ballx,bally,p1,XOR_PUT);
if(score==(48*5)-((4-chance)*20))
{
settextstyle(7,0,4);
outtextxy(midx,midy,"YOU WIN!!!");
if(score<240)
{
outtextxy(midx,midy+30,"Try to score 240");
getch();
}
else
{
outtextxy(midx,midy+30,"You are simply great!");
music(3);
getch();
}
closegraph();
restorecrtmode();
exit(0);
}
delay(speed);
if(kbhit())
{
ii.h.ah=0;
int86(22,&ii,&oo);
putimage(paddlex,paddley,p2,OR_PUT);
putimage(paddlex,paddley,p2,XOR_PUT);
if(oo.h.ah==1)
exit(0);
if(oo.h.ah==75)
paddlex=paddlex-20;
if(oo.h.ah==77)
paddlex=paddlex+20;
if(paddlex<1)
paddlex=1;
if(paddlex>588)
paddlex=588;
putimage(paddlex,paddley,p2,XOR_PUT);
}
}
}
mainscreen()
{
int ff[12][40]={
1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,
1,1,0,0,1,0,0,0,0,1,0,0,0,1,1,1,0,1,0,0,0,1,0,
0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,
0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,
1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,1,
0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,
0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,1,
0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,
0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,
1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,
0,0,0,0,0,1,1,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,
0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,
0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,
0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,
0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,
1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,1,0,0,0,
0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,1,
0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,0,1,1,1,1,1,
0,0,0,1,1,1,0,0,1,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0
};
int i,j,lx=1,ly=0,ch;
/*draw boundary */
rectangle(0,0,maxx,maxy);
/* from the word bricks*/
for (i=0;i<12;i++)
{
for (j=0;j<40;j++)
{
if(ff[i][j])
{
setfillstyle(SOLID_FILL,RED);
rectangle(lx,ly,lx+15,ly+9);
floodfill(lx+3,ly+3,WHITE);
}
lx = lx+16;
}
lx=0;
ly=ly+10;
}
/*draw pattern at the bottom of the screen */
line(0,maxy-12,maxx,maxy-12);
setfillstyle(XHATCH_FILL,WHITE);
/*draw the paddle and the ball*/
setfillstyle(SOLID_FILL,WHITE);
rectangle(midx-25,maxy-7-12-20,midx+25,maxy-12-20);
circle(midx,maxy-13-12-50,12);
music(3);
/*display menu*/
while(1)
{
/*clear the region below the word BRICKS*/
setviewport(1,125-12,maxx-1,maxy-1,1);
clearviewport();
setviewport(0,0,maxx,maxy,1);
setcolor(WHITE);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(20,235,"Select any of the following:");
outtextxy(20,265,"Play(P)");
outtextxy(20,295,"Instructions(!)");
outtextxy(20,325,"Exit(E)");
ch=0;
/*continue till the correct choice is made */
while(!(ch=='E'||ch=='|'||ch =='P'))
{
fflush(stdin);
/*if a special key is hit, flush the keyboard buffer*/
if((ch=getch())==0)
getch();
else
ch=toupper(ch);
}
if(ch=='P')
break;
switch(ch)
{
case'|':
setviewport(1,125-12,maxx-1,maxy-1,1);
clearviewport();
setviewport(0,0,maxx,maxy,1);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(20,200,"Instructions:-");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(20,240,"Use left and right arrow keys to move paddle");
outtextxy(20,270,"If you don't collect a ball on the paddle, you lose the ball");
outtextxy(20,300,"On loosing the ball you loose 20 points");
outtextxy(20,330,"On taking a brick you gain 5 points");
outtextxy(20,365,"Press any key...");
fflush(stdin);
if (getch()==0)
getch();
break;
case 'E':
closegraph();
restorecrtmode();
exit(0);
}
}
setviewport(1,125-12,maxx-1,maxy-1,1);
cleardevice();
setviewport(0,0,maxx,maxy,1);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(20,150,"Select any of the following levels:");
outtextxy(20,200,"Novice(N)");
outtextxy(20,245,"Advance(A)");
outtextxy(20,290,"Expert(E)");
fflush(stdin);
if((ch=getch())==0)
getch();
cleardevice();
return(ch);
}
bricks()
{
int i,j,lx=0,ly=0;
for(i=0;i<3;i++)
{
for(j=0;j<=16;j++)
{
drawbricks(lx,ly);
lx=lx+40;
}
lx=0;
ly=ly+25;
}
}
vBulletin v3.5.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.