我目前正在使用 AS3 创建一个 Flash 游戏,并且目前已经达到了用户能够使用键盘使玩家角色在舞台上移动的地步。我目前有两个具有独特名称的敌人在编译游戏时被添加到舞台上。
我目前所坚持的是检测玩家离哪个敌人最近,并只让那个敌人旋转并向玩家移动。
public function updateEnemies(player:MovieClip):void{
//run a for loop on our array and update every enemy object in there
for(var i = 0; i < enemyObjectsArray.length; i++){
var enemy:Object = enemyObjectsArray[i];
//calculate distance between enemyObject's movieClip and target
enemy.distanceX = player.x - enemy.myMc.x;
enemy.distanceY = player.y - enemy.myMc.y;
enemy.distanceTotal = new Point(enemy.myMc.x - player.x, enemy.myMc.y - player.y);
trace(enemy.distanceTotal);
//sort the array based on the enemy object's "distanceTotal" parameter
enemyObjectsArray.sortOn("distanceTotal", Array.NUMERIC);
enemyObjectsArray[0].myMc.rotation = 10;
}
}