用途別リファレンス

旋回しながらプレイヤーを追いかける敵

Main
$player=new Player{x:250,y:250};
new Enemy{x:200,y:100};
new Enemy{x:300,y:100};
new Enemy{x:400,y:300};
new Enemy{x:100,y:300};

Enemy
//移動方向の角度
dir=0;
while (true) {
    //オブジェクトの見た目を回転させる
    rotation=dir;
    //dirの方向に移動する
    x+=cos(dir);
    y+=sin(dir);
    //(tx,ty)の場所を目指して移動
    //この例では$playerの位置
    tx=$player.x;
    ty=$player.y;
    //自分の位置からの(tx,ty)の角度
    tdir=atanxy(tx-x, ty-y);
    //移動方向とtdirを比較し、
    d=angleDiff(dir,tdir);
    //どちらに旋回するかを決める
    if (d>0) dir-=2;
    else dir+=2;
    
    update();
}

Player
//プレイヤーの動作を書く(とりあえず何も書かなくてもよい)