4实现部分的关键代码(AS2) 4.1粒子类:
import SMotion.*
import SColDet.*
class SPhy.CSPhyMc extends MovieClip
{
public var m:Number=0;//mass
public var g:Number=0;//gravity
public var pF:Number=0;//Positive forces,attention here UpCase!!!!!!!
//Because the compiler was not so perfect as you think ,add a p here to prepare for the case.
public var r:Number =0;//when it become a ball---radius.
public var v :Number=0;//1 demision Velocity or together Velocity of vx ,vy
public var vx:Number=0;
public var vy:Number=0;
public var f :Number=0;//fraction forces.
public var fx:Number=0;
public var fy:Number=0;
public var a :Number=0;//acclerate v
public var ax:Number=0;
public var ay:Number=0;
//plane game use;
public var bigFire:Number=0;
private static var DEAD:Number=0;
private static var LIVED:Number=1;
private var life:Number;
private var mMotionCom:RCSMove;
private var mColDetCom:RCSColDet;
private static var thisP:Object;
public function setLife(lifeValue:Number):Void
{
life=lifeValue;
}
public function getLife():Number
{
return life;
}
public function isLived():Boolean
{
return life==LIVED;
}
public function init():Void
{
thisP=this;
this.vx=0;
this.vy=0;
this.v=3+random(3);
this._width=10;
this._height=10;
this.r=5;
this.initCom();
}
public function initPos(targetPlane:CSPhyMc):Void
{
var randNum:Number=random(100);
//set init positoin:down,left,up,right
if(randNum<25)
{
this._x=random(Stage.width);
trace("Width"+Stage.width+"Height"+Stage.height);
this._y=Stage.height;
}
else if(randNum<50)
{
thisP._x=_root.gStageLeft;
this._y=random(Stage.height);
}
else if(randNum<75)
{
this._x=random(Stage.width);
thisP._y=_root.gStageTop;
}
else
{
this._x=Stage.width;
this._y=random(Stage.height);
}
this.CalVx_Vy(this,targetPlane);
}
private function GetDis(mc1:CSPhyMc, mc2:CSPhyMc):Number
{
return Math.sqrt((mc1._x-mc2._x)*(mc1._x-mc2._x)+(mc1._y-mc2._y)*(mc1._y-mc2._y));
}
private function CalVx_Vy(mcChase:CSPhyMc, mcAim:CSPhyMc):Void
{
var len:Number= GetDis(mcChase, mcAim);
mcChase.vx=(mcAim._x-mcChase._x)/len*mcChase.v;
mcChase.vy=(mcAim._y-mcChase._y)/len*mcChase.v;
}
public function initCom():Void
{
mMotionCom=new RCSMove();
mColDetCom=new RCSColDet();
}
public function outDetect():Boolean
{
var offset:Number=25;
return mColDetCom.particleOutDet(this,0-offset,0-offset,Stage.width+2*offset,Stage.height+2*offset);
}
public function move_show():Void
{
mMotionCom.Move2D(this,this.vx,this.vy);
}
public function collideDect(targetPlane:CSPhyMc):Boolean
{
if(_root.mcLibPlaneName=="ball")
return mColDetCom.TwoBall(targetPlane,this);
//return this.hitTest(targetPlane.getBounds(_root).xMin,targetPlane.getBounds(_root).yMax,false);
}
}