C赛车游戏Word下载.docx
《C赛车游戏Word下载.docx》由会员分享,可在线阅读,更多相关《C赛车游戏Word下载.docx(12页珍藏版)》请在冰豆网上搜索。
stdlib.h>
const
u
=
26;
i
2;
j
3;
road(void)
{
h;
for(h=0;
h<
4;
h++)
line(150+h*100,0,150+h*100,472);
setlinestyle(3,0,1);
line(200+h*100,0,200+h*100,472);
settextstyle(1,HORIZ_DIR,3);
tree(void)
w;
poly[14];
setcolor(10);
for
(w=-3;
w<
w=w+2)
line(85
-25+u*15+w*157
85
35+u*15+w*157);
line(95
95
line(105
105
line(115
115
line(75
-9+u*15+w*157
75
19+u*15+w*157);
line(125
125
(w=-2;
poly[0]
530;
poly[1]
u*15+w*157;
poly[2]
=515;
poly[3]
25+u*15+w*157;
poly[4]
=485;
poly[5]
=25+u*15+w*157
;
poly[6]
=470;
poly[7]
=u*15+w*157
poly[8]
poly[9]
=-25+u*15+w*157;
poly[10]
poly[11]
=-25+u*15+w*157
poly[12]
poly[0];
poly[13]
poly[1];
drawpoly(7,poly);
truck(void)
setcolor
(2);
rectangle(170+i*100,j*10,230+i*100,60+j*10);
rectangle(160+i*100,70+j*10,240+i*100,260+j*10);
line(180+i*100,70+j*10,180+i*100,260+j*10);
line(200+i*100,70+j*10,200+i*100,260+j*10);
line(220+i*100,70+j*10,220+i*100,260+j*10);
car(void)
main(void)
gdriver
DETECT
gmode,w;
gdriver,
&
setcolor(WHITE);
road();
tree();
truck();
car();
在来说一下赛车游戏
我上面给大家可以说是从第一步:
制作简单的场景和玩家的赛车
到第二步:
进一步完善场景,
大家可能已经有所领会
下面我们就把它做成一个简单的游戏
代码如下:
static
c=1;
e=0;
u=0;
v=0;
x=1;
y=0;
j=-21;
i;
b;
begin(void)
xmax,
ymax;
startx,starty,endx,endy;
setbkcolor(WHITE);
xmax
getmaxx();
ymax
getmaxy();
endx=20;
endy=20;
startx=10;
starty=10;
setcolor(RED);
settextstyle(1,HORIZ_DIR,4);
outtextxy(10,240,"
Bus
Bus"
outtextxy(300,300,"
Made
by
PU
BIN."
setcolor(GREEN);
while(startx<
xmax&
starty<
ymax)
rectangle(startx,starty,endx,endy);
delay(4);
startx+=2;
starty+=startx*startx/2000;
endx=startx+10;
endy=starty+10;
sound(startx*10);
delay(10);
nosound();
cleardevice();
outtextxy(40,40,"
PASS"
outtextxy(40,80,"
1"
rectangle(150,400,450,460);
outtextxy(160,410,"
Ready,Begin!
math(void)
if(x==2)
2"
else
if(x==3)
3"
if(x==4)
4"
}else
if(x==5){
5"
if(x==6){
6"
if(x==7){
7"
if(x==8){
8"
if(x==9){
9"
if(x==10){
10"
if(x==11){
11"
if(x==12){
12"
if(x==13){
13"
if(x==14){
14"
if(x==15){
15"
if(x==16){
16"
if(x==17){
17"
if(x==18){
18"
if(x==19){
19"
if(x==20){
20"
if(x==21){
21"
if(x==22){
22"
if(x==23){
23"
if(x==24){
24"
if(x==25){
25"
y=1;
v=1;
bus2(void)
setcolor(BLUE);
rectangle(180+c*100,350,220+c*100,390);
rectangle(170+c*100,340,230+c*100,350);
rectangle(190+c*100,320,210+c*100,340);
rectangle(170+c*100,390,230+c*100,400);
setcolor(5);
line(190+c*100,350,190+c*100,390);
line(200+c*100,350,200+c*100,390);
line(210+c*100,350,210+c*100,390);
line(200+c*100,300,200+c*100,320);
line(185+c*100,300,215+c*100,300);
if((b==0x4b00)&
(c>
0))
c--;
else
if((b==0x4d00)&
(c<
2))
c++;
if((b==0x5000)&
sleep
(1);
rectangle(180+c*100,350,220+c*100,390);
rectangle(170+c*100,340,230+c*100,350);
light(void)
rectangle(535,65,565,155);
floodfill(545,100,BLUE);
setfillstyle(1,RED);
fillellipse(550,80,10,10);
sound(650);
delay(300);
nosound();
delay(100);
setfillstyle(1,YELLOW);
fillellipse(550,110,10,10);
sound(650);
setfillstyle(1,GREEN);
fillellipse(550,140,10,10);
setlinestyle(SOLID_LINE,0,3);
rectangle(150,400,450,460);
outtextxy(160,410,"
brock(void)
if((c==i)&
(j>
4)&
(j<
38))
e=1;
line(85,-25+u*15+w*157,85,35+u*15+w*157);
line(95,-25+u*15+w*157,95,35+u*15+w*157);
line(105,-25+u*15+w*157,105,35+u*15+w*157);
line(115,-25+u*15+w*157,115,35+u*15+w*157);
line(75,-9+u*15+w*157,75,19+u*15+w*157);
line(125,-9+u*15+w*157,125,19+u*15+w*157);
bus1(void)
randomize();
i=random(3);
do
if((x!
=7)&
(x!
=16)&
=23))
setcolor(x);
else
rectangle(160+i*100,70+j*10,240+i*100,260+j*10);
line(200+i*100,70+j*10,200+i*100,260+j*10);
line(220+i*100,70+j*10,220+i*100,260+j*10);
tree();
sound(j*10);
u++;
j++;
brock();
if(e==1)
j=48;
u=63;
}while((bioskey
(1)==0)&
=47)&
(u<
=62));
if((j<
=62))
/*
function
0
returns
the
key
that
is
waiting
*/
b=
bioskey(0);
bus2();
if(u<
=62)
randomize();
i=rand()%3;
x++;
math();
setcolor(x);
}while(y!
=1);
end()
if
(v==1)
for(j=0;
j<
94;
j++)
rectangle(150,j*5,450,60+j*5);
settextstyle(1,HORIZ_DIR,4);
outtextxy(160,10+j*5,"
STOP!
You
win!
sound(500+j*10);
delay
(2);
outtextxy(160,10+j*5,"
}
closegraph();
printf("
\n\nyou
if(v==0
)
printf("
\n\nYou
lose."
\n\n\nCome
back
again.\n\n
YOU
LIAO
w