📄 0039.c
字号:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include"stdlib.h"
#include<math.h>
#include"dos.h"
#define PATH ""
#define r 10.0
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define Enter 0x1c0d
#define DELETE 0x5300
#define END 0x4f00
int run=0;
struct balltype
{
float x,y;
float dx,dy;
int flag;
}
ball[1];
int x=310,y=260; /*准星的起始点坐标*/
float power=15.0;
int hole[6][2]={ {570,425},{290,425},{50,425},
{50,160},{290,160},{570,160}};
qudong()
{
/*int DETECT; */
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
cleardevice();/*清屏*/
}
dong()
{
/*setcolor(0); */ /*dai1*/
/*setfillstyle(8,15);*/
circle(570,425,12);
/*floodfill(570,425,0);*/
/*setcolor(0); */ /*dai2*/
/*setfillstyle(8,15);*/
circle(290,425,12);
/*floodfill(290,425,0);*/
/*setcolor(0); */ /*dai3*/
/*setfillstyle(8,15);*/
circle(50,425,12);
/*floodfill(50,425,0);*/
/*setcolor(0);*/
/*setfillstyle(8,15);*/ /*dai4*/
circle(50,160,12);
/*floodfill(50,160,0);*/
/*setcolor(0); */ /*dai5*/
/*setfillstyle(8,15);*/
circle(290,160,12);
/*floodfill(290,160,0);*/
/*setcolor(0); */ /*dai6*/
/*setfillstyle(8,15);*/
circle(570,160,12);
/*floodfill(570,160,0);*/
}
huamian()
{
setbkcolor(1);
setfillstyle(1,6);
bar(30,140,590,445);/*游戏区*/ /*a rectangle*/
setfillstyle(1,2);
bar(50,160,570,425); /*b*/
}
/********************************力量*/
void drawpower()
{
int i;
gotoxy(25,4); /*力量条的坐标*/
printf("power==[");
for(i=0;i<power;i++)printf(">");
for(i=35-power;i>0;i--)printf("-");
printf("]");
}
go()
{
float m;
m=atan2(y-ball[0].y,x-ball[0].x); /*求前/后的反正切值*/
ball[0].dx=(power/2.5)*cos(m); /*发射后0号球的位置横坐标*/
ball[0].dy=(power/2.5)*sin(m); /*发射后0号球的位置纵坐标*/
}
play ()
{
int key,i;
ball[0].x=310;
ball[0].y=260;
ball[0].dx=0;
ball[0].dy=0; /*前面那个球。把球的坐标与其中一个球的坐标重合就好了,真苯!*/
while(1)
{
while(!kbhit())
{
setfillstyle(1,2); /*球心会变成绿色*/
setcolor(2);
circle(ball[0].x,ball[0].y,10); /*通过调节这里可以让游戏看上去更完美一些*/
floodfill(ball[0].x,ball[0].y,2);
ball[0].x+=ball[0].dx;
ball[0].y+=ball[0].dy;
setfillstyle(1,15);
setcolor(15);
circle(ball[0].x,ball[0].y,10);
floodfill(ball[0].x,ball[0].y,15);
drawpower();
if(run==0) /*停止 */
{
}
ball[0].dx*=0.95;
ball[0].dy*=0.95;
delay(50000000000000);
if(ball[0].x<60||ball[0].x>560) /*边界反弹50,160,570,425*/
{ ball[0].dx=-ball[0].dx ;}
if(ball[0].y<170||ball[0].y>415)
{ball[0].dy=-ball[0].dy; }
setcolor(15);
line(ball[0].x,ball[0].y,x,y);
setcolor(15);
circle(x,y,10);
setcolor(2); /*修改此处改正了线的颜色,且不在刷拉*/
circle(x,y,10); /*准星的其始圆*/
line(ball[0].x,ball[0].y,x,y);
setfillstyle(1,15);
setcolor(15);
circle(ball[0].x,ball[0].y,10); /*球的起始点*/
floodfill(ball[0].x,ball[0].y,15);
dong();
for(i=0;i<6;i++) /*判断进洞*/
{
if((pow(fabs(ball[0].x-hole[i][0]),2)+pow(fabs(ball[0].y-hole[i][1]),2))<169)
{ ball[0].flag=0; /*可以进洞。进洞后停止的判断、*/
ball[0].dx=0; /*出始点的判断*/
ball[0].dy=0;
setcolor(2);
circle(ball[0].x,ball[0].y,10);
setcolor(0);
setfillstyle(1,0);
circle(hole[i][0],hole[i][1],10);
floodfill(hole[i][0],hole[i][1],0);
dong();
}
if(ball[0].flag==0)
{
ball[0].flag=1;
ball[0].x=182;
ball[0].y=260;
setcolor(2);
circle(ball[0].x,ball[0].y,10);
}
else if(ball[0].flag==1)
{
setcolor(15);
circle(ball[0].x,ball[0].y,10);
}
}}
key=bioskey(0);
switch(key) /*对这里的改动可以改变球标移动时的擦球的问题*/
{
case UP:{ setcolor(2);
line(ball[0].x,ball[0].y,x,y);
circle(x,y,10);
y--;
}
break;
case LEFT:{
setcolor(2);
line(ball[0].x,ball[0].y,x,y);
circle(x,y,10);
x--;
}
break;
case DOWN:
{
setcolor(2);
line(ball[0].x,ball[0].y,x,y);
circle(x,y,10);
y++;
}
break;
case RIGHT:{
setcolor(2);
line(ball[0].x,ball[0].y,x,y);
circle(x,y,10);
x++;
}
break;
case Enter:{
go();
}
break;
case DELETE: power++; /*力量增加*/
if(power>35)power=35;
break;
case END: power--; /*力量减少*/
if(power<0)power=0;
break;
case ESC: exit(0);
}
setcolor(15); /*瞄准星*/
setlinestyle(2,0,1);
line(ball[0].x,ball[0].y,x,y);
circle(x,y,10);
setlinestyle(0,0,1);
} }
main()
{
qudong();
huamian();
play();
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -