Displaying Source Code(s)
|
|
A car game. You have to drive the car in such a way that you
dont strike a barrier on the road.
--------------------------------------------------------------------------------
{
Description: A car game. You have to drive the car in such a way
that you dont strike a barrier on the road.
}
program hero;
uses graph,crt;
const dir='c: p gi';
var
x1,x2,x3,driver,mode,moder,left1,left2,right1,right2:integer;
y1,y2,y3,lan1,lan2,chan,s1,s2,s3,s4,r1,r2:integer;
c,r,menu:char;
left,right,crash:boolean;
Procedure sides1(x,y,a,b,c:integer);
Begin
If c mod 2 =0 then
Begin
setcolor(red);
rectangle(x,y,a,b);
setfillstyle(1,red);
floodfill(x+2,b-5,red);
End
Else
Begin
setcolor(white);
rectangle(x,y,a,b);
setfillstyle(1,white);
floodfill(x+2,b-5,white);
End;
End;
Procedure sides2(x,y,a,b,c:integer);
Begin
If c mod 2 =0 then
Begin
setcolor(white);
rectangle(x,y,a,b);
setfillstyle(1,white);
floodfill(x+2,b-5,white);
End
Else
Begin
setcolor(red);
rectangle(x,y,a,b);
setfillstyle(1,red);
floodfill(x+2,b-5,red);
End;
End;
procedure lane1(d,e,f:integer);
var a1,a2:integer;
Begin
a1:=315;
a2:=325;
if f mod 2 = 0 then
Begin
setcolor(white);
rectangle(a1,d,a2,e);
setfillstyle(1,white);
floodfill(317,e-5,white);
End
else
Begin
setcolor(black);
rectangle(a1,d,a2,e);
setfillstyle(1,black);
floodfill(317,e-5,black);
End;
end;
procedure lane2(d,e,f:integer);
var a1,a2:integer;
Begin
a1:=315;
a2:=325;
if f mod 2 = 0 then
Begin
setcolor(black);
rectangle(a1,d,a2,e);
setfillstyle(1,black);
floodfill(317,e-5,black);
End
else
Begin
setcolor(white);
rectangle(a1,d,a2,e);
setfillstyle(1,white);
floodfill(317,e-5,white);
End;
End;
procedure rukawat1(a:integer);
begin
setfillstyle(1,7);
floodfill(220,a-5,7);
end;
procedure rukawat2(a:integer);
begin
setfillstyle(1,black);
floodfill(220,a-5,black);
end;
procedure rukawat3(a:integer);
begin
setfillstyle(1,7);
floodfill(420,a-5,7);
end;
procedure rukawat4(a:integer);
begin
setfillstyle(1,black);
floodfill(420,a-5,black);
end;
Procedure obst1;
Begin
setcolor(7);
rectangle(s1,r1,s2,r2);
rukawat1(r2);
delay(200);
rectangle(s1,r1,s2,r2);
rukawat2(r2);
End;
Procedure obst2;
Begin
setcolor(7);
rectangle(s3,r1,s4,r2);
rukawat3(r2);
delay(200);
rectangle(s3,r1,s4,r2);
rukawat4(r2);
End;
procedure car(x,y:integer);
begin
setcolor(white);
line(x,y,x+50,y); {horizontal line}
line(x,y,x-10,y+10); {left intersecting line}
line(x+50,y,x+60,y+10); {right intersecting line}
line(x-10,y+10,x-10,y+30); {left st line}
line(x+60,y+10,x+60,y+30); {right st line}
line(x-10,y+30,x+60,y+30); {end of bonnet}
setfillstyle(1,blue);
floodfill(x+20,y+20,white);
rectangle(x+60,y+30,x+70,y+35); {right side view mirror}
setfillstyle(1,7);
floodfill(x+65,y+33,white);
rectangle(x-20,y+35,x-10,y+30); {left side view mirror}
setfillstyle(1,7);
floodfill(x-15,y+33,white);
line(x-10,y+30,x-10,y+100); {body side left}
line(x+60,y+30,x+60,y+100); {body side right}
line(x-10,y+30,x,y+45); {wind screen left}
line(x+60,y+30,x+50,y+45); {wind screen right}
rectangle(x,y+45,x+50,y+80); {main roof}
setfillstyle(1,blue);
floodfill(x+2,y+50,white);
line(x+20,y+30,x,y+35 ); {left wiper}
line(x+50,y+30,x+30,y+35); {right wiper}
rectangle(x+10,y+50,x+40,y+60); {sunroof}
setfillstyle(1,8);
floodfill(x+20,y+55,white);
line(x,y+60,x-10,y+60); {left door}
line(x+50,y+60,x+60,y+60); {right door}
line(x,y+80,x-10,y+100); {roof to body side left}
line(x+50,y+80,x+60,y+100); {roof to body side right}
line(x-10,y+100,x+60,y+100); {back wind screen}
rectangle(x-10,y+100,x+60,y+115);
setfillstyle(1,blue);
floodfill(x+20,y+110,white);
line(x,y+100,x+20,y+87); {back windscreen wiper}
rectangle(x-20,y+115,x+70,y+130); {racing car's special raised
trunk}
setfillstyle(1,blue);
floodfill(x,y+120,white);
line(x-10,y+122,x+60,y+122); {racing car's (back) trunk
horizontaly 1 }
end;
procedure car2(x,y:integer);
begin
setcolor(black);
line(x,y,x+50,y); {horizontal line}
line(x,y,x-10,y+10); {left intersecting line}
line(x+50,y,x+60,y+10); {right intersecting line}
line(x-10,y+10,x-10,y+30); {left st line}
line(x+60,y+10,x+60,y+30); {right st line}
line(x-10,y+30,x+60,y+30); {end of bonnet}
setfillstyle(1,black);
floodfill(x+20,y+20,black);
rectangle(x+60,y+30,x+70,y+35); {right side view mirror}
setfillstyle(1,black);
floodfill(x+65,y+33,black);
rectangle(x-20,y+35,x-10,y+30); {left side view mirror}
setfillstyle(1,black);
floodfill(x-15,y+33,black);
line(x-10,y+30,x-10,y+100); {body side left}
line(x+60,y+30,x+60,y+100); {body side right}
line(x-10,y+30,x,y+45); {wind screen left}
line(x+60,y+30,x+50,y+45); {wind screen right}
rectangle(x,y+45,x+50,y+80); {main roof}
setfillstyle(1,black);
floodfill(x+2,y+50,black);
line(x+20,y+30,x,y+35 ); {left wiper}
line(x+50,y+30,x+30,y+35); {right wiper}
rectangle(x+10,y+50,x+40,y+60); {sunroof}
line(x,y+60,x-10,y+60); {left door}
line(x+50,y+60,x+60,y+60); {right door}
line(x,y+80,x-10,y+100); {roof to body side left}
line(x+50,y+80,x+60,y+100); {roof to body side right}
line(x-10,y+100,x+60,y+100); {back wind screen}
rectangle(x-10,y+100,x+60,y+115);
setfillstyle(1,black);
floodfill(x+20,y+110,black);
line(x,y+100,x+20,y+87); {back windscreen wiper}
rectangle(x-20,y+115,x+70,y+130); {racing car's special raised
trunk}
setfillstyle(1,black);
floodfill(x,y+120,black);
line(x-10,y+122,x+60,y+122); {racing car's (back) trunk
horizontaly 1}
end;
Procedure option;
Begin
while keypressed =true do
Begin
c:=readkey;
case c of
'j':Begin
car2(365,330);
car(300,330);
delay(30);
car2(300,330);
car(210,330);
left:=true;
right:=false;
End;
'l':Begin
car2(210,330);
car(300,330);
delay(30);
car2(300,330);
car(365,330);
right:=true;
left:=false;
End;
'q': Begin
y1:=450;
End;
End;
End;
End;
{----------------------------MAIN
BODY-----------------------------------}
Begin
initgraph(driver,mode,dir);
setbkcolor(7);
randomize;
setcolor(1);
settextstyle(4,horizdir,7);
outtextxy(230,90,'MENU');
settextstyle(2,horizdir,7);
outtextxy(100,170,'PRESS THE FOLLOWING KEYS TO PLAY OR QUIT');
outtextxy(250,220,'1: START');
outtextxy(250,250,'2: QUIT');
outtextxy(240,310,'DURING GAME');
outtextxy(180,360,'TO TURN CAR LEFT PRESS J');
outtextxy(180,390,'TO TURN CAR RIGHT PRESS L');
outtextxy(180,420,'PRESS Q TO QUIT');
menu:=readkey;
while keypressed =true do
Begin
menu:=readkey;
End;
Case menu of
'1':Begin
cleardevice;
setbkcolor(black);
setcolor(green);
rectangle(0,0,160,480);
setfillstyle(1,green);
floodfill(100,30,green);
rectangle(480,0,640,480);
setfillstyle(1,green);
floodfill(500,400,green);
setcolor(white);
car(210,330);
car2(365,330);
left:=true;
crash:=false;
Repeat {--------------MAIN LOOP-----------------}
y1:=0;
y2:=25;
lan1:=0; {MIDDLE LANE}
lan2:=50; {MIDDLE LANE}
left1:=160;
left2:=170;
right1:=470;
right2:=480;
moder:=0;
s1:=200;
s2:=275;
s3:=360;
s4:=435;
r1:=110;
r2:=120;
chan:=random(20);
Repeat
moder:=moder+1;
option;
sides1(left1,y1,left2,y2,moder); {left side}
sides1(right1,y1,right2,y2,moder);{right side}
lane1(lan1,lan2,moder);
delay(5);
sides2(left1,y1,left2,y2,moder); {Left side alternate}
sides2(right1,y1,right2,y2,moder); {Right side alternate}
lane2(lan1,lan2,moder);
Case chan of
0,1,2:Begin
if r1<470 then
obst1;
if (r1=470)and (left=true) then
Begin
crash:=true;
End;
r1:=r1+120;
r2:=r1+10;
End;
5,6,7:Begin
if r1<470 then
obst2;
if (r1=470)and (right=true) then
Begin
crash:=true;
End;
r1:=r1+120;
r2:=r1+10;
End;
End;
lan1:=lan1+50;
lan2:=lan1+50;
y1:=y1+25;
y2:=y1+25;
option;
If lan1=450 then
Begin
lan1:=0;
lan2:=50;
End;
Until(y1=450)or(crash=true);
Until(c='q')or(crash=true);
cleardevice;
setbkcolor(cyan);
If crash= true then
Begin
setcolor(red);
settextstyle(2,horizdir,10);
outtextxy(220,220,'GAME OVER');
outtextxy(100,280,'THANK YOU FOR PLAYING');
readkey;
End;
if c='q' then
Begin
setcolor(red);
settextstyle(2,horizdir,8);
outtextxy(150,220,'YOU HAVE CHOSEN TO QUIT');
readkey;
End;
End;
'2':Begin
cleardevice;
setbkcolor(cyan);
setcolor(red);
settextstyle(2,horizdir,8);
outtextxy(150,220,'YOU HAVE CHOSEN TO QUIT');
readkey;
End;
End;
End.
-------------------------------------------------------------------------------- |
|
|