📄 init1.c
字号:
/*单人足球的初始化工作*/
void InitPitch(FootballPitch *pitch);
void DrawPitch(FootballPitch *pitch);
void InitBall(Football *ball,FootballPitch pitch);
int InitRobot(Robot *dubuying,FootballPitch pitch,Football ball);
int InitIndicator(Football *ball,Robot *dubu);
void InitPitch(FootballPitch *pitch)
{
pitch->color=GREEN;
pitch->position[0]=70;
pitch->position[1]=60;
pitch->position[2]=570;
pitch->position[3]=390;
}
void DrawPitch(FootballPitch *pitch)
{
setfillstyle(1,pitch->color);
bar(50,50,590,400);
setlinestyle(0,0,2);
line(90,60,550,60);
line(90,390,550,390);
line(70,80,70,370);
line(570,80,570,370);
line(90,60,70,80);
line(550,60,570,80);
line(70,370,90,390);
line(570,370,550,390);
line(320,60,320,390);
circle(320,225,40);
rectangle(70,120,160,330);
rectangle(480,120,570,330);
rectangle(70,170,110,280);
rectangle(530,170,570,280);
arc(125,225,0,45,50);
arc(125,225,315,360,50);
arc(515,225,135,180,50);
arc(515,225,180,225,50);
setlinestyle(0,0,1);
setfillstyle(8,WHITE);
bar(55,200,70,250);
bar(570,200,585,250);
setcolor(WHITE);
}
void InitBall(Football *ball,FootballPitch pitch)
{
float x,y;
randomize();
ball->init_speed=2.5;
ball->radius=3;
ball->color=WHITE;
ball->ball_x=(pitch.position[0] + pitch.position[2]) / 2 + 150;
ball->ball_y=(pitch.position[1] + pitch.position[3]) / 2 + 100;
do{
x=random(50);
y=random(50);
}while(x>y);
ball->direction_angle=(x/y)*2*PI;
ball->friction_factor=0.02;
}
int InitRobot(Robot *dubuying,FootballPitch pitch,Football ball)
{
dubuying->number=1;
dubuying->team='A';
dubuying->sidelength=20;
dubuying->color=RED;
dubuying->position_x=(pitch.position[0]+pitch.position[2])/2;
dubuying->position_y=(pitch.position[1]+pitch.position[3])/2;
dubuying->small_speed=2;
dubuying->big_speed=2.2;
dubuying->forward_speed=1.8;
dubuying->decline=(dubuying->big_speed - dubuying->small_speed)/(dubuying->sidelength/2);
dubuying->reverse_radius=dubuying->sidelength/2*sqrt(2);
dubuying->direction_indicator=0;
return 0;
}
int InitIndicator(Football *ball,Robot *dubu)
{
if(ball->ball_x > dubu->position_x)
dubu->direction_indicator = 0;
else dubu->direction_indicator = PI;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -