📄 core2.c
字号:
int important2(Football *ball,Robot *team1,Robot *team2,FootballPitch *pitch);
/*2人足球的核心部分*/
int important2(Football *ball,Robot *team1,Robot *team2,FootballPitch *pitch)
{
int size1,size2,size3,i,x;
void *buffer1,*buffer2,*buffer3;
InitIndicator(ball,team1);
InitIndicator(ball,team2);
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,team1);
if(x==1)
TurnToBall(ball,team1);
else MoveToBall(ball,team1);
x=WhetherInView(ball,team2);
/*向球的方向旋转*/
if(x==1)
TurnToBall(ball,team2);
else MoveToBall(ball,team2);
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(team1->position_x - team1->reverse_radius,team1->position_y - team1->reverse_radius,team1->position_x + team1->reverse_radius,team1->position_y + team1->reverse_radius);
buffer2 = malloc(size2);
getimage(team1->position_x - team1->reverse_radius,team1->position_y - team1->reverse_radius,team1->position_x + team1->reverse_radius,team1->position_y + team1->reverse_radius,buffer2);
size3 = imagesize(team2->position_x - team2->reverse_radius,team2->position_y - team2->reverse_radius,team2->position_x + team2->reverse_radius,team2->position_y + team2->reverse_radius);
buffer3 = malloc(size3);
getimage(team2->position_x - team2->reverse_radius,team2->position_y - team2->reverse_radius,team2->position_x + team2->reverse_radius,team2->position_y + team2->reverse_radius,buffer3);
DrawBall(ball);
DrawRobot(team1);
DrawRobot(team2);
delay(15);
MeetBoundary(ball,pitch);
MeetRobot(ball,team1);
MeetRobot(ball,team2);
/* 判断是否进球 */
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(team1->position_x - team1->reverse_radius,team1->position_y - team1->reverse_radius,buffer2,COPY_PUT);
putimage(team2->position_x - team2->reverse_radius,team2->position_y - team2->reverse_radius,buffer3,COPY_PUT);
free(buffer1);
free(buffer2);
free(buffer3);
}
free(buffer1);
free(buffer2);
free(buffer3);
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 + -