资源预览内容
第1页 / 共23页
第2页 / 共23页
第3页 / 共23页
第4页 / 共23页
第5页 / 共23页
第6页 / 共23页
第7页 / 共23页
第8页 / 共23页
第9页 / 共23页
第10页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
#include #include #include #include #include #include #define G 9.8 /*重力加速度*/#define PI 3.141593 /*圆周率*/#define L1 60 /*小屋运动的范围*/#define T1 100#define R1 200#define B1 450#define AMD1 7.8 /*修订数 7.8*/#define AMD2 1.78 /*修订数*/*鼠标信息宏定义*/ #define WAITING 0xff00 #define LEFTPRESS 0xff01 #define LEFTCLICK 0xff10 #define LEFTDRAG 0xff19 #define RIGHTPRESS 0xff02 #define RIGHTCLICK 0xff20 #define RIGHTDRAG 0xff2a #define MIDDLEPRESS 0xff04 #define MIDDLECLICK 0xff40 #define MIDDLEDRAG 0xff4c #define MOUSEMOVE 0xff08int Keystate; int MouseExist; int MouseButton; int MouseX; int MouseY; int up1616,down1616,mouse_draw1616,pixel_save1616; void MouseMath()/*计算鼠标的样子*/ int i,j,jj,k; long UpNum16= 0x3fff,0x1fff,0x0fff,0x07ff, 0x03ff,0x01ff,0x00ff,0x007f, 0x003f,0x00ff,0x01ff,0x10ff, 0x30ff,0xf87f,0xf87f,0xfc3f ; long DownNum16= 0x0000,0x7c00,0x6000,0x7000, 0x7800,0x7c00,0x7e00,0x7f00, 0x7f80,0x7e00,0x7c00,0x4600, 0x0600,0x0300,0x0300,0x0180 ; for(i=0;i=0;k-) upik=0; for(k=jj;k=0;k-) downik=0; for(k=0;kx1)return 4;elsereturn 0;elses=(int)(double)(y1-y2)/(double)(x1-x2)*(double)(qx-x1)+(double)(y1);if(qys)return 2;elsereturn 0;/*根据两点坐标计算出两点距离和向量(twoxy0-twoxy2,twoxy1-twoxy3)与(vectorx,vectory)的夹角。*/void DistanceAngle (int twoxy4,int vectorx,int vectory,double *distance,double *angle)double a,b;double s;if(twoxy0=twoxy2)&twoxy1=twoxy3)*distance=0;*angle=0;elseb=(double)(double)(twoxy3-twoxy1)*(double)(twoxy3-twoxy1)+(double)(twoxy2-twoxy0)*(double)(twoxy2-twoxy0);b=sqrt(b);*distance=b;s=(double)(double)(vectorx)*(double)(vectorx)+(double)(vectory)*(double)(vectory);s=sqrt(s);a=(double)(double)(twoxy0-twoxy2)*(double)(vectorx)+(double)(twoxy1-twoxy3)*(double)(vectory);a=a/(b*s);a=acos(a);if(twoxy3=twoxy1)*angle=a;else*angle=a+(PI-a)*2;/*由速度角度算 sx,sy 随时间的变化*/void RelativePosition(int *sx,int *sy,double v,double angle,double t)*sx=(int)(v*cos(angle)*t);*sy=(int)(v*sin(angle)*t-0.5*G*t*t);/*用鼠标画一条直线,把直线的两点坐标放在 twoxy 数组内。*/void TwoPoints(int twoxy4,int dx,int dy)int i,q=1;double speed=0.0,angle=0.0;twoxy0=0;twoxy1=0;setcolor(13);line(0,dy,640,dy);setcolor(4); MouseOn();/*显示鼠标*/setwritemode(1);i=0; while(q) if(i=1)MouseOff();DistanceAngle(twoxy,1,0,&speed,&angle);AngleSpeed(speed/AMD1,angle);InitialArrow (dx,dy,twoxy);setcolor(4); line(twoxy0,twoxy1,twoxy2,twoxy3);MouseOn();if(twoxy2!=MouseX)|(twoxy3!=MouseY)twoxy2=MouseX;twoxy3=MouseY;/*PointCircle(twoxy0,twoxy1,50,&(twoxy2),&(twoxy3);*/MouseOff();DistanceAngle(twoxy,1,0,&speed,&angle);AngleSpeed(speed/AMD1,angle);InitialArrow (dx,dy,twoxy);setcolor(4); line(twoxy0,twoxy1,twoxy2,twoxy3);MouseOn();if(MouseStatus()sound(1000);/*响声函数*/ delay(10000);nosound();delay(1000000);delay(1000000);delay(1000000);delay(1000000);if(i=0)twoxy0=MouseX;twoxy1=MouseY;twoxy2=MouseX;twoxy3=MouseY;i=1;elseMouseOff();DistanceAngle(twoxy,1,0,&speed,&angle);AngleSpeed(speed/AMD1,angle);InitialArrow (dx,dy,twoxy);setcolor(4); line(twoxy0,twoxy1,twoxy2,twoxy3);setcolor(13);line(0,dy,640,dy);q=0;i=0; /*发射箭,speed1 和 speed2 控制速度,返回中弹位置*/int Launch(int lx,int ly,int tx,int ty,int hm,int grade)double speed1=0.01;int speed2=1000;int a4;int xx2,xy2;double s=0.0,angle=0.0,t=0.0;lx=lx;ly=ly-40;if(hm=3)a0=lx;a1=ly; a2=tx;a3=ty;Fire (a,&s,&angle,grade); elseTwoPoints(a,lx,ly);DistanceAngle(a,1,0,&s,&angle);s=s/AMD1;RelativePosition(&xx0,&xy0,s,angle,t-1);RelativePosition(&xx1,&xy1,s,angle,t);for(t=0.0;ly-xy1640-1)return 0;PictureBullets (lx+xx0,ly-xy0,lx+xx1,ly-xy1);delay(speed2);PictureBullets (lx+xx0,ly-xy0,lx+xx1,ly-xy1);return 0;/*小屋移动的函数*/int MoveRen(struct Ren *p)int a,k=19200,b=0,d;int q=1;randomize();for(;q;)if(b=1)p-lr=3;RenPicture(p-x,p-y,p-color);if(p-lr=3)b=1;delay(10000);delay(10000);delay(10000);delay(10000);delay(10000);delay(10000);/sleep(1);d=random(10); if(d=0)k=19200;if(d=1)k=19712;if(d=2)k=18432;if(d=3)k=20480;if(d=4)k=7181;p-lr=1; elsek=bioskey(0);RenPicture(p-x,p-y,p-color);switch(k)case 19200: /*按向左键*/a=(p-x)-5;if(p-lr=1)if(aL1&ax=a;break;else if(a640-R1&ax=a;break;break;case 19712: /*按向右键*/ a=(p-x)+5;if(p-lr=1)if(aL1&ax=a;break;else if(a640-R1&ax=a;break; break;case 18432: /*按向上键*/ a=(p-y)-5;if(p-lr=1)if(aT1&ay=a;break;else if(aT1&ay=a;break; break;case 20480: /*按向下键*/a=(p-y)+5;if(aT1&ay=a;break;case 7181: /*enter 键的扫描码*/if(b=1)p-lr=3;q=0;break;case 283: return 0;RenPicture(p-x,p-y,p-color);return 1;/*游戏开始前画面*/int GameStar()/*返回 1 表示单人游戏初级,2 表示单人游戏中级,3 表示单人游戏高级,4 表示两人对战,5 表示退出游戏*/int q,k,h=0;for(;1;) q=1;cleardevice();/*清屏函数*/setcolo
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号