敌人经理级AS3

时间:2013-10-26 20:28:51

标签: windows actionscript-3 gamekit

我怎样才能让一个跨越线路的敌人向我们的玩家扔东西?

我想用ActionScript 3做,我已经有enemy_manager类了 我已经有了获取角度的代码

var dx : Number = point1.x - point2.x;
var dy : Number = point1.y - point2.y;
var angleInRadians : Number = Math.atan2(dy, dx);
var andleInDegrees : Number = angleInRadians * (180 / Math.PI);

1 个答案:

答案 0 :(得分:0)

我认为你的问题是如何通过射弹速度将十进制值变为多倍,以使射弹朝向玩家。这是完成该任务的代码。

        var projectileSpeed:Number=30 (pixels a second)
        var dx : Number = point2.x - point1.x;
        var dy : Number = point2.y - point1.y;
        var angleInRadians : Number = Math.atan2(dy, dx);
        var angleInDegrees : Number = angleInRadians * (180 / Math.PI);

        this.directionX = Math.cos(angleInRadians) * projectileSpeed; // Turns the angleInRadians into a decimal value
        // For example ( 180 degrees would be 1 PI and the cos() and sin() would make directionX=-1 and directionY=0
        this.directionY = Math.sin(angleInRadians) * projectileSpeed;

        projectile.rotation = angleInDegrees; // makes it face where it is going ( if you event want this)
        ...
        private function loop(e:Event):void { // loop to show the projectile move
          // Updates the projectile's positions using directionX and directionY
          projectile.x += directionX;
          projectile.y += directionY;
    }