?? 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 + -