import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.geom.Point;
import zujian.Tank;
public class Paodan extends Sprite
{
private var ball:Ball;
private var point:Point=new Point();
private var dx:Number;
private var dy:Number;
private var vx:Number;
private var vy:Number;
private var paodan:Paodan;
private var speed:Number=8;
private var stg:Stage;
public function Paodan()
{
ball = new Ball();
this.addChild(ball);
}
public function beginFly(paodan:Paodan,stage:Stage,tanke:Tank){
this.paodan=paodan;
this.stg = stage;
point.x=stg.mouseX;
point.y=stg.mouseY;
dx=point.x-tanke.x;
dy=point.y-tanke.y;
var angle:Number = Math.atan2(dy, dx); //計算方塊對滑鼠位置的角度
vx = Math.cos(angle) * speed; //x方向移動距離/每楨
vy = Math.sin(angle) * speed; //y方向移動距離/每楨
paodan.x += vx*5.5;
paodan.y += vy*5.5;
this.paodan.addEventListener(Event.ENTER_FRAME,fly);
}
private function fly(evt:Event):void{
var point:Point = new Point();
point.x = paodan.x;
point.y = paodan.y;
var arr:Array=stg.getObjectsUnderPoint(point);
if(arr.length>1){
this.paodan.removeEventListener(Event.ENTER_FRAME,fly);
}
paodan.x += vx;
paodan.y += vy;
}
}