0

我怎样才能让一个敌人越过这条线并向我们的玩家扔东西?

我想用 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);
4

1 回答 1

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;
    }
于 2013-10-27T17:28:10.780 回答