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); // calculates the angle of the square to the mouse position
VX = math. Cos (angle) * speed; // The moving distance in the X direction/
Vy = math. Sin (angle) * speed; // The Y-direction moving distance.
Paodan. x + = VX * 5.5;
Pamaxan. 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;
}
}