?? dancer.c
字號:
#include <airobot/c/SimpleRobot.h>
//在一個方向上最大的移動時間
#define MOVE_TIME 25
//移動的方向,這個變量的值只能取1和-1,1表示前進,-1表示后退
int direction = 1;
//當前在一個方向上的移動時間
long moveTime = 0;
//設置移動的方向
void setDirection(void);
//執(zhí)行移動
void doMove(void);
//執(zhí)行轉(zhuǎn)動
void doTurn(void);
//得到圓心位置
void getCenter(double* x, double* y);
void onTick(struct TickAction* action)
{
setDirection();
doMove();
doTurn();
}
void setDirection(void)
{
moveTime++;
if(moveTime>MOVE_TIME)
{
direction *= -1; //變換移動方向
moveTime = 0;
}
}
void doMove(void)
{
move(10*direction);
}
void doTurn(void)
{
double centerX, centerY, lineHeading, headingTo, bea;
getCenter(¢erX, ¢erY);
lineHeading = heading(getX(), getY(), centerX, centerY);
headingTo = lineHeading + PI/2;
bea = bearing(headingTo, getHeading());
turn(bea);
}
void getCenter(double* x, double* y)
{
struct Bot* bot = getFirstOpponent();
if(bot==NULL)
{
*x = getCourtWidth()/2;
*y = getCourtHeight()/2;
}
else
{
*x = bot->x;
*y = bot->y;
}
}
//啟動機器人程序
int main(int argC, char* argV[])
{
tickHook = onTick;
return startup(argC, argV);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -