#<graphics.h>
#<conio.h>
#<stdio.h>
#<stdlib.h>
#<alloc.h>
# ESC 0x1b /*ESCASCII码十 6进制数*/
void InstallGraph(void); /*图形化声明*/
void DrawGun(void); /*画发射架声明*/
void DrawPlan(void); /*画火箭声明*/
void DrawStar(void); /*画星声明*/
void *buf; /*全局变量用于存储火箭图像*/
x0=300; /*以下是火箭位置化参数*/
y0=340;
width1=5;
width2=20;
height=25;
y1=8;
y2=15;
y3=23;
y4=38;
{
size;
i=0;
key;
station;
InstallGraph;
bkcolor(BLACK); /*设置背景颜色*/
cleardevice;
color(BLUE); /*设置字颜色*/
outtextxy(80,100,\"Ready!...Any key to SET OFF !!!\");
DrawGun;
getch;
cleardevice;
DrawGun;
DrawPlan;
DrawStar;
color(LIGHTRED);
do{putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);/*主循环开始用于移动火箭思路方法是用异或方式在屏幕上连续画出火箭图像每画次新图像和原来位置相差两个像素点这个值越大飞行速度越快*/
i2;
putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);
key=getch;
(y0-height-3*width1-i0)
outtextxy(60,100,\"Successfully!!! Press ESC to quit\");
(keyESC)
{
(y0-height-3*width1-i>0){
cleardevice;
outtextxy(100,100,\"Failue. What did you do?\");
outtextxy(130,300,\"Press any key to quit.\");
getch;
}
}
}
while(key!=ESC);
free(buf);
closegraph;
0; }
void InstallGraph(void) /*图形化*/
{
grdriver=DETECT;
grmode;
errorcode;
char *errormsg;
initgraph(&grdriver,&grmode,\" \");
errorcode=graphresult;
errormsg=grapherrormsg(errorcode);
(errorcode!=grOk){
prf(\"Graphics error: %s\\n\",errormsg);
prf(\"Press any key to exit.\\n\");
getch;
exit(1);
}
}
void DrawStar(void) /*画星*/
{
seed=2000;
i,dotx,doty,height,width,color,maxcolor;
maxcolor=getmaxcolor;
width=getmaxx;
height=getmaxy;
srand(seed);
for(i=0;i<250;i){
dotx=i+random(width-1);
doty=i+random(height-1);
color=random(maxcolor);
color(color);
putpixel(dotx,doty,color);
circle(dotx+1,doty+1,1);
}
srand(seed);
}
void DrawGun(void) /*画发射架*/
{
x0=300;
y0=430;
height=45;
rx=20;
ry=5;
rightx,righty,leftx,lefty;
centery1=30;
rightx=righty=leftx=lefty=12;
color(LIGHTGREEN);
ellipse(x0,y0,180,360,rx,ry);
ellipse(x0,y0-height,0,360,rx,ry);
line(x0+rx,y0,x0+rx,y0-height);
line(x0-rx,y0,x0-rx,y0-height);
moveto(x0+rx,y0);
lineto(x0+rx+rightx,y0+righty);
moveto(x0+rx+rightx,y0+righty);
lineto(x0+rx+rightx+10,y0+righty+10);
circle(x0+rx+rightx+10,y0+righty+10,4);
moveto(x0,y0+ry);
lineto(x0,y0+centery1);
moveto(x0,y0+centery1);
lineto(x0,y0+centery1+10);
circle(x0,y0+centery1+10,4);
moveto(x0-rx,y0);
lineto(x0-rx-leftx,y0+lefty);
moveto(x0-rx-leftx,y0+lefty);
lineto(x0-rx-leftx-10,y0+lefty+10);
circle(x0-rx-leftx-10,y0+lefty+10,4);
line(x0-rx-leftx,y0+lefty,x0,y0+centery1);
line(x0,y0+centery1,x0+rx+rightx,y0+righty);
}
void DrawPlan(void) /*发射火箭*/
{
size;
color(LIGHTRED);
fillstyle(1,BLUE);
ellipse(x0,y0-height,0,180,width1,3*width1);
moveto(x0+width1,y0);
lineto(x0+width1,y0-height);
moveto(x0+width1,y0);
lineto(x0+width2,y0+y2);
moveto(x0-width1,y0);
lineto(x0-width1,y0-height);
moveto(x0-width1,y0);
lineto(x0-width2,y0+y2);
moveto(x0+width2,y0+y3);
lineto(x0+width2,y0+y1);
moveto(x0+width2,y0+y3);
lineto(x0+width1,y0+y2);
moveto(x0-width2,y0+y3);
lineto(x0-width2,y0+y1);
moveto(x0-width2,y0+y3);
lineto(x0-width1,y0+y2);
moveto(x0,y0+y4);
lineto(x0+width1,y0+y2);
moveto(x0,y0+y4);
lineto(x0-width1,y0+y2);
fillstyle(2,LIGHTRED);
floodfill(x0,y0,LIGHTRED);
size=imagesize(x0-width2-1,y0-height-3*width1,x0+width2+1,y0+y4);
buf=malloc(size);
(!buf){prf(\"No enough memory!\");
exit(0);}
getimage(x0-width2,y0-height-3*width1,x0+width2,y0+y4,buf);
}
最新评论