📄 core1.c
字号:
int important(Football *ball,Robot *dubu,FootballPitch *pitch);
/*单人足球的核心部分*/
int important(Football *ball,Robot *dubu,FootballPitch *pitch)
{
int size1,size2,i,x;
void *buffer1,*buffer2;
InitIndicator(ball,dubu);
for(i=0; ;i++)
{ /*球的运动*/
ball->init_speed -= ball->friction_factor;
if((ball->init_speed) > 0.1)
{
ball->ball_x += (ball->init_speed) * cos(ball->direction_angle);
ball->ball_y -= (ball->init_speed) * sin(ball->direction_angle);
}
/*判断球是否在机器人的正对面*/
x=WhetherInView(ball,dubu);
/*向球的方向旋转*/
if(x==1)
TurnToBall(ball,dubu);
else MoveToBall(ball,dubu);
size1 = imagesize(ball->ball_x - ball->radius,ball->ball_y - ball->radius,ball->ball_x + ball->radius,ball->ball_y + ball->radius);
buffer1 = malloc(size1);
getimage(ball->ball_x - ball->radius,ball->ball_y - ball->radius,ball->ball_x + ball->radius,ball->ball_y + ball->radius,buffer1);
size2 = imagesize(dubu->position_x - dubu->reverse_radius,dubu->position_y - dubu->reverse_radius,dubu->position_x + dubu->reverse_radius,dubu->position_y + dubu->reverse_radius);
buffer2 = malloc(size2);
getimage(dubu->position_x - dubu->reverse_radius,dubu->position_y - dubu->reverse_radius,dubu->position_x + dubu->reverse_radius,dubu->position_y + dubu->reverse_radius,buffer2);
DrawBall(ball);
DrawRobot(dubu);
delay(15);
/*当球发生碰撞后新的角度和速度*/
WhetherReflect(ball,dubu,pitch,i);
/*判断是否进球*/
if(fabs(ball->ball_x - 55) <= 4 || fabs(ball->ball_x - 585) <= 4)
break;
else if(fabs(ball->ball_y - 200) <= 4 && (ball->ball_x < 70 || ball->ball_x > 570))
break;
else if(fabs(ball->ball_y - 250) <= 4 && (ball->ball_x < 70 || ball->ball_x > 570))
break;
putimage(ball->ball_x - ball->radius,ball->ball_y - ball->radius,buffer1,COPY_PUT);
putimage(dubu->position_x - dubu->reverse_radius,dubu->position_y - dubu->reverse_radius,buffer2,COPY_PUT);
free(buffer1);
free(buffer2);
}
free(buffer1);
free(buffer2);
setcolor(RED);
settextstyle(0,0,5);
settextjustify(1,1);
outtextxy(320,430,"GOAL!");
setcolor(WHITE);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -