我正在使用以下 Enemy Class,敌人不会以准确的角度朝向舞台中心。那么我应该对我的代码进行哪些更改才能更准确地工作呢?
{
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;
}
}
}