Gallardo Racing


#include<graphics.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<dos.h>


int i=0;
void drawgallardo(int x,int y,int color=14)
{
setcolor(6);
setfillstyle(SOLID_FILL,6);
fillellipse(x,y,12,12);
fillellipse(x+95,y,12,12);
setcolor(8);
setfillstyle(SOLID_FILL,8);


sector(x,y,90+x,135+x,12,12);
sector(x,y,270+x,315+x,12,12);
sector(x+95,y,90+x,135+x,12,12);
sector(x+95,y,270+x,315+x,12,12);


setcolor(color);
line(x+10,y+10,x+83,y+8);
line(x-20,y,x-12,y+8);
line(x+105,y+10,x+123,y+11);
line(x+123,y+11,x+129,y+1);
arc(x,y,308,220,14);
arc(x+95,y,308,220,14);
line(x-20,y,x-20,y-23);
arc(x+8,y+235,79,96,260);
arc(x+85,y+210,100,110,250);
arc(x+48,y+16,55,122,50);
arc(x+25,y+79,60,76,120);
arc(x+50,y+13,82,103,50);
arc(x-6,y+148,47,55,200);
arc(x,y+210,63,70,250);
line(x+57,y-22,x+78,y-24);


setfillstyle(SOLID_FILL,color);
floodfill(x+30,y-5,color);


//side style
setcolor(4);
arc(x+87,y-42,201,216,70);
arc(x+90,y-42,201,216,70);
line(x+18,y-17,x+60,y-14);
line(x+21,y-14,x+60,y-14);
line(x+22,y-1,x+65,y);
line(x+26,y-4,x+65,y);
}




void erase(int x,int y)
{
setfillstyle(SOLID_FILL,BLACK);
bar(x-35,y-45,x+130,y+12);
bar(0,getmaxy()/2-20,getmaxx(),getmaxy()/2+20);
}




int main()
{
int gd=DETECT,gm,x=40,y,j,x1,y2,color=2,free=1,time,level=0,sublevel=0,lives=3,score=0;
char ch;
randomize();
initgraph(&gd,&gm,"c:\\tc\\bgi");
y=getmaxy()/2;
x1=getmaxx()-40;
y2=y;
setcolor(WHITE);
setfillstyle(SOLID_FILL,WHITE);
for(j=0;j<15;j+=2)
{
rectangle(j*40,getmaxy()/2-20,50+j*40,getmaxy()/2-10);
floodfill(j*40+2,getmaxy()/2-20+2,WHITE);
}
setcolor(GREEN);
line(0,getmaxy()/2-125,getmaxx(),getmaxy()/2-125);
line(0,getmaxy()/2+90,getmaxx(),getmaxy()/2+90);
setfillstyle(SOLID_FILL,GREEN);
floodfill(1,1,GREEN);
floodfill(getmaxx(),getmaxy(),GREEN);
gotoxy(1,1);
cout<<"UP/DOWN key to move the car";
gotoxy(1,2);
cout<<"RIGHT key to use nitrous   ";
gotoxy(1,3);
cout<<"p to pause the game        ";
gotoxy(70,23);
cout<<"score:   ";
gotoxy(36,25);
cout<<"level:   ";
gotoxy(4,23);
cout<<"lives:   ";
gotoxy(36,27);
cout<<"Speed:   ";


while(1)
{
      
gotoxy(77,23);
cout<<score;
gotoxy(43,27);
cout<<(level+1)*40;
gotoxy(43,25);
cout<<level;
gotoxy(11,23);
cout<<lives;
setcolor(WHITE);
setfillstyle(SOLID_FILL,WHITE);
for(j=0;j<20+level;j+=2)
{
rectangle(j*40-(level+1)*10*i,getmaxy()/2-20,50+j*40-(level+1)*10*i,getmaxy()/2-10);
floodfill(j*40+10-(level+1)*10*i,getmaxy()/2-20+2,WHITE);
}


if(i==8)
{i=0;}


time=100-(level*20);
i++;




if(x1<=10)
{
free=random(3)+1;
x1=getmaxx()-40;
color=random(16);
score=score+10;
sublevel++;
if(sublevel==7)
{
sublevel=0;
level++;
if(level==6)
{
cleardevice();
gotoxy(34,16);
cout<<"YOU WON THE RACE";
gotoxy(34,20);
cout<<"Your Score: "<<score;
getch();
closegraph();
return 0;
}
gotoxy(36,16);
cout<<"NEXT LEVEL";
delay(1500);
gotoxy(36,16);
cout<<"          ";
}
}


//accident
if((x+100)>=(x1-35))
{
if( (free==1&&y!=(getmaxy()/2-65)) || (free==2&&y!=(getmaxy()/2)) || (free==3&&y!=(getmaxy()/2+65)) )
{
if(lives==0)
{
cleardevice();
gotoxy(30,14);
cout<<"YOU CRASHED A GALLARDO";
gotoxy(36,16);
cout<<"GAME OVER";
gotoxy(34,20);
cout<<"Your Score: "<<(sublevel*10)+(level*70);
getch();
closegraph();
return 0;
}
lives--;
gotoxy(33,16);
cout<<"YOU LOST A LIFE";
sublevel=0;
delay(1500);
gotoxy(34,16);
cout<<"               ";
x1=getmaxx()-40;
}
}




if(kbhit())
{
ch=getch();
switch (ch)
{


case 80://down
if(y<(getmaxy()/2)+60)
{
y=y+65;
}
break;


case 72://up
if(y>(getmaxy()/2)-60)
{
y=y-65;
}
break;


case 77://nitrous
x1=x1-60;
setfillstyle(SOLID_FILL,WHITE);
bar(0,y,30,y+12);
break;


case 112:
gotoxy(36,16);
cout<<"Game Paused";
while(!kbhit())
{}
gotoxy(36,16);
cout<<"            ";


break;


case char(27):
gotoxy(35,16);
cout<<"Come again";
getch();
closegraph();
return 0;


}//end of switch
}//end of if


//draw the car
if(x!=40)
x=40;
else
x=x+3;
x1=x1-21;
j=color;
drawgallardo(x,y);
if(free!=1)
drawgallardo(x1,y2-65,color=color?color:3);
if(free!=2)
drawgallardo(x1,y2,color=(--color)?color:6);
if(free!=3)
drawgallardo(x1,y2+65,color=(--color)?color:11);
color=j;
delay(time);


//erase the car
erase(x,y);
if(free!=1)
erase(x1,y2-65);
if(free!=2)
erase(x1,y2);
if(free!=3)
erase(x1,y2+65);


}//end of while
}//end of main

Comments

Popular Posts