Saturday, July 21, 2007

Car

// ----- Program to display a moving car ----- kn
#include
#include
#include
#include
void car(int x), go(), wheel(int c);
int color=4,speed=50,e,x=0,stangle = 0,endangle = 180,radius = 30;
// ----- Program starts here
void main()
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "");
go();
getch();
}//End of main program
// ----- Function to move the car
void go()
{
int i=0;
char c;
line(0,280,650,280);
outtextxy(390,10,"[R] Red colour");
outtextxy(390,20,"[G] Green colour");
outtextxy(390,30,"[B] Blue colour");
outtextxy(540,10,"[F] Fast");
outtextxy(540,20,"[S] Slow");
outtextxy(390,40,"[x] Exit CAR");
outtextxy(380,450,"Developed by Kailas, S7 CS, MCET");
while(1)
{
if(kbhit()) //to detect whether there is any key stroke
{
c=getch();
if(c=='x' || c=='X') // if key pressed is x or X then exit
exit(0);
else if(c=='R'||c=='r') // Red car
color=4;
else if(c=='B'||c=='b') // Blue car
color=1;
else if(c=='G'||c=='g') // Green car
color=2;
else if(c=='F'||c=='f') // Fast
speed=1;
else if(c=='S'||c=='s') // Slow
speed=50;
}
i++;
setcolor(0);
wheel(0);
car(x);
x=i+5;
setcolor(color);
car(x);
wheel(7);
delay(speed);
if(i==600)
i=-150;
}
}
// ----- Design of Car
void car(int x)
{
line(80+x,100,225+x,100); // top roof
line(80+x,100,50+x,175); // back glass
line(50+x,175,50+x,250); // back door
line(225+x,100,300+x,175); // front glass
line(300+x,175,380+x,195); // bonet
arc(380+x, 216, 0, 90, 20);
line(400+x,216,400+x,250); // front grill
e=50+x; // -------------
line(e,250,e+10,250); // bottom -
line(e+70,250,e+240,250); // platform -
line(e+300,250,e+350,250); // -------------
arc(e+40, 250, stangle, endangle, radius);
arc(e+270, 250, stangle, endangle, radius);
//front door
line(215+x,105,215+x,240); //left
line(285+x,170,285+x,240); //right
line(215+x,105,220+x,105); //top
line(215+x,240,285+x,240); //bottom
line(220+x,105,285+x,170); // front slope
line(220+x,110,220+x,170);
line(220+x,170,280+x,170);
line(220+x,110,280+x,170);
//back door
line(130+x,105,130+x,240); //left
line(210+x,105,210+x,240); //right
line(130+x,105,210+x,105); //top
line(130+x,240,210+x,240); //bottom
rectangle(135+x,110,205+x,170); //window
rectangle(80+x,110,125+x,170); //back window
}
// -----Design of the wheels of car
void wheel(int c)
{
setcolor(c);
circle(e+40, 250, radius-4);
circle(e+270, 250, radius-4);
circle(e+40, 250, radius-3);
circle(e+270, 250, radius-3);
rectangle(30+x,185,45+x,235); // extra tyre
}
/*-------

No comments: