As3 shell flight and collision Algorithm

Source: Internet
Author: User

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;
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.