<=pianx+1 || qx+r>=(tx+jx)*8+pianx-1) {flag=-flag;k=-k;} if(qy-r<=piany+1) k=-k; for(gi=0;gi<5;gi++) {l=1; for(gj=0;gj<16;gj++) { if((zhuan[gi]&l)==0) {j=(16*gi+gj)/8; i=(16*gi+gj)%8; x=(jx+tx)*i+jx+tx/2+pianx; y=(jy+ty)*j+jy+ty/2+piany; /*边判断1*/ if(qy>=y-ty/2 && qy<=y+ty/2 &&(pow(qx+r-x+tx/2,2)<1 || pow(qx-r-x-tx/2,2)<1)) {flag=-flag;k=-k; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) {printf("Win!\n");getch();goto star;} setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty) *j+piany+jy+ty); } else /*边判断2*/ if(qx> ;=x-tx/2 && qx<=x+tx/2 &&(pow(qy+r-y+ty/2,2)<1 || pow(qy-r-y-ty/2,2)<1)) {k=-k; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) {printf("Win!\n");getch();goto star;} setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty) *j+piany+jy+ty); } else /*角判断*/ if(pow(qx-x+tx/2,2)+pow(qy-y+ty/2,2)<=r*r || pow(qx-x-tx/2,2)+pow(qy-y+ty/2,2)<=r*r || pow(qx-x+tx/2,2)+pow(qy-y-ty/2,2)<=r*r || pow(qx-x-tx/2,2)+pow(qy-y-ty/2,2)<=r*r) {flag=-flag; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) {printf("Win!\n");getch();goto star;} setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty) *j+piany+jy+ty); } }l=l*2;}} /*棍棒的反弹*/ if(qx<=mx+bx/2 && qx>=mx-bx/2 && pow(qy+r-my,2)<1) {k=-(k/pow(k*k,0.5))*(0.3*bx/(pow(pow (qx-mx,2),0.5)+0.000001));} if((int)(qy+r)>my+0.5) {printf("DEAD!");Setmouse(0,0,640,480);getch();exit(1);} b=qy-qx*k; if(flag==1) qx=qx+speech/pow(1.0+k*k,0.5); if(flag==-1) qx=qx-speech/pow(1.0+k*k,0.5); qy=qx*k+b;/*计算球心坐标*/ setcolor(14); circle((int)qx,(int)qy,r); delay(1); if(mb==1) {Setmouse(0,0,640,480);exit(1);} } } /*这个函数用于实现鼠标的初始化*/ int Msinit() {int recored; regs.x.ax=0; int86 (0x33, & regs, & regs); recored=regs.x.ax; if(recored==0) {printf("Mouse not foundd or Mouse driver not installed.\n"); return 0; } else return recored; } /*下面的函数用于实现设置鼠标的移动范围*/ void Setmouse(int left,int right,int top,int buttom) { regs.x.ax=7; regs.x.cx=left; regs.x.dx=right; int86(0x33,& regs,& regs); regs.x.ax=8; regs.x.cx=top; regs.x.dx=buttom; int86(0x33,& regs,& regs); } /*下面这个函数用于实现鼠标的读取*/ int Msread(int *xp,int *yp,int *bup) {int xnew,ynew,ch; if(kbhit()) return getch(); regs.x.ax=3; int86(0x33,& regs,& regs); xnew=regs.x.cx; ynew=regs.x.dx; *bup=regs.x.bx; *xp=xnew; *yp=ynew; return -1; } /*下面这个子程序是完成描绘一个按钮*/ void Draw(int x,int y,int sizex,int sizey)/* x, y为左上角坐标sizex,sizey为长和宽*/ {int sizx=sizex-1; int sizy=sizey-1; setcolor(15);/*这里最好用白色*/ line(x,y,x+sizx-1,y); line(x,y+1,x+sizx-2,y+1); line(x,y,x,y+sizy-1); line(x+1,y,x+1,y+sizy-2); setcolor(8);/*这里最好用深灰色*/ line(x+1,y+sizy,x+sizx,y+sizy); line(x+2,y+sizy-1,x+sizx,y+sizy-1); line(x+sizx-1,y+1,x+sizx-1,y+sizy); line(x+sizx,y+2,x+sizx,y+sizy); setcolor(7);/*这里最好用灰色*/ putpixel(x,y+sizy,3); putpixel(x+1,y+sizy-1,3); putpixel(x+sizx,y,3); putpixel(x+sizx-1,y+1,3); setfillstyle(1, 7);/*这里最好用灰色,设置填充模式*/ bar(x+2,y+2,x+sizx-2,y+sizy-2); } 参考资料: 。
4. 教你如何使用C语言编写简单小游戏 //声明#include#include#include#include