as3炮弹飞行和碰撞算法

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

 }

你可能感兴趣的:(算法,function,Class,import)