次の敵クラスを使用していますが、敵はステージの中心に向かって正確な角度で来ていません。では、コードをより正確に機能させるには、コードにどのような変更を加える必要がありますか?
{
import flash.display.MovieClip;
import flash.events.*;
import flash.display.Stage;
public class Enemy1 extends MovieClip
{
private var BG:MovieClip;
private var speed:Number = 0.5;
public function Enemy1(BG:MovieClip) : void
{
var RandomX:Array = new Array(100,200,300,400,800,900,1000,1100);
var RandomY:Array = new Array(100,200,300,600,700,800);
var r:int = (Math.random() * 8);
var s:int = (Math.random() * 6);
x = RandomX[r];
y = RandomY[s];
this.BG = BG;
addEventListener(Event.ENTER_FRAME, moveEnemy); //false, 0, true);.
}
private function moveEnemy(e:Event):void
{
if (this.x > 660)
{
this.x -= speed;
this.rotation = 180;
}
if (this.x < 540)
{
this.x += speed;
this.rotation = 0;
}
if (this.y > 510)
{
this.y -= speed;
this.rotation = 270;
}
if (this.y < 390)
{
this.y += speed;
this.rotation = 90;
}
if (this.x > 660 && this.y > 510)
{
this.x -= speed;
this.y -= speed;
this.rotation = 225;
}
if (this.x < 540 && this.y < 390)
{
this.x += speed;
this.y += speed;
this.rotation = 45;
}
if (this.x < 540 && this.y > 510)
{
this.x += speed;
this.y -= speed;
this.rotation = 315;
}
if (this.x > 660 && this.y < 390)
{
this.x -= speed;
this.y += speed;
this.rotation = 135;
}
}
}