home *** CD-ROM | disk | FTP | other *** search
- class Missile
- {
- var bAlly;
- var bExp;
- var bmpMissile;
- var bmpCanvas;
- var position;
- var velMax;
- var velLin;
- var velocity;
- var rotation;
- var acc;
- var screenPos;
- var frameExp;
- function Missile(sLinkageId, pos, refTarget, bAllyNew)
- {
- this.bAlly = true;
- this.bExp = false;
- this.bmpMissile = flash.display.BitmapData.loadBitmap(sLinkageId);
- if(this.bAlly)
- {
- this.bmpCanvas = Game.bmpShots;
- }
- else
- {
- this.bmpCanvas = Game.bmpDead;
- }
- this.position = pos.clone();
- this.velMax = 15;
- this.velLin = 0;
- this.velocity = new flash.geom.Point();
- var _loc2_ = refTarget.getPosition();
- var _loc4_ = _loc2_.x - this.position.x;
- var _loc3_ = _loc2_.y - this.position.y;
- this.rotation = Math.atan2(_loc3_,_loc4_);
- this.acc = new flash.geom.Point();
- this.draw();
- }
- function step(refTarget, bAlly)
- {
- if(this.bExp)
- {
- return undefined;
- }
- var _loc6_ = refTarget.getPosition();
- var _loc4_ = _loc6_.x - this.position.x;
- var _loc3_ = _loc6_.y - this.position.y;
- var _loc2_ = Math.atan2(_loc3_,_loc4_);
- var _loc5_ = _loc2_ - this.rotation;
- if(_loc2_ / this.rotation < 0)
- {
- if(_loc2_ > 0 && _loc5_ > 3.141592653589793)
- {
- _loc2_ -= 6.283185307179586;
- }
- else if(_loc2_ < 0 && _loc5_ < -3.141592653589793)
- {
- _loc2_ += 6.283185307179586;
- }
- }
- this.rotation += (_loc2_ - this.rotation) * 0.2;
- var _loc8_ = this.velocity.length;
- if(this.velLin < this.velMax)
- {
- this.velLin += 0.15;
- }
- else
- {
- this.velLin = this.velMax;
- }
- this.velocity.x = this.velLin * Math.cos(this.rotation);
- this.velocity.y = this.velLin * Math.sin(this.rotation);
- this.position.x += this.velocity.x;
- this.position.y += this.velocity.y;
- if(this.screenPos.x < -200 || this.screenPos.x > Game.screenW + 200)
- {
- if(bAlly)
- {
- Game.getInstance().removeAllyMissile(this);
- }
- else
- {
- Game.getInstance().removeHostileMissile(this);
- }
- }
- if(Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_) < 30)
- {
- refTarget.getDamage(100);
- if(bAlly)
- {
- Game.getInstance().removeAllyMissile(this);
- }
- else
- {
- Game.getInstance().removeHostileMissile(this);
- }
- }
- if(Game.bmpDead.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(this.screenPos.x,Game.screenH - this.screenPos.y)))
- {
- this.bExp = true;
- this.frameExp = 0;
- }
- }
- function draw(leftEdge)
- {
- var _loc6_ = this.position.x - leftEdge;
- var _loc5_ = this.position.y;
- this.screenPos = new flash.geom.Point(_loc6_,_loc5_);
- if(this.bExp)
- {
- this.drawExplosion(this.screenPos,true);
- }
- else
- {
- var _loc2_ = new flash.display.BitmapData(this.bmpMissile.width,this.bmpMissile.height,true,0);
- _loc2_.copyPixels(this.bmpMissile,this.bmpMissile.rectangle,new flash.geom.Point(0,0),null,null,true);
- var _loc3_ = new flash.geom.Matrix();
- _loc3_.translate((- _loc2_.width) / 2,(- _loc2_.height) / 2);
- var _loc7_ = new flash.geom.Matrix();
- _loc7_.rotate(- this.rotation);
- _loc3_.concat(_loc7_);
- var _loc4_ = new flash.geom.Matrix();
- _loc4_.translate(_loc6_,Game.screenH - _loc5_);
- _loc3_.concat(_loc4_);
- var _loc9_ = null;
- var _loc8_ = "normal";
- var _loc10_ = null;
- var _loc11_ = true;
- this.bmpCanvas.draw(_loc2_,_loc3_,_loc9_,_loc8_,_loc10_,_loc11_);
- }
- }
- function drawExplosion(pos, bRemove)
- {
- var _loc4_ = _root.attachMovie("explosion0","mcExp",_root.getNextHighestDepth());
- _loc4_.gotoAndStop(this.frameExp + 1);
- var _loc5_ = new flash.geom.Matrix();
- _loc5_.translate(pos.x,Game.screenH - pos.y);
- var _loc3_ = new flash.geom.Matrix();
- _loc3_.scale(0.5,0.5);
- _loc3_.concat(_loc5_);
- this.bmpCanvas.draw(_loc4_,_loc3_,null,null,null,true);
- _loc4_.removeMovieClip();
- this.frameExp = this.frameExp + 1;
- if(this.frameExp == 25)
- {
- if(bRemove)
- {
- this.onEndDeadAnim();
- }
- }
- }
- function onEndDeadAnim(Void)
- {
- if(this.bAlly)
- {
- Game.getInstance().removeAllyMissile(this);
- }
- else
- {
- Game.getInstance().removeHostileMissile(this);
- }
- }
- function findNearest(aObjects)
- {
- var _loc8_ = aObjects.length;
- var _loc5_ = 1.7976931348623157e+308;
- var _loc7_ = null;
- var _loc2_ = 0;
- while(_loc2_ < _loc8_)
- {
- var _loc3_ = aObjects[_loc2_].getPosition();
- _loc3_.subtract(this.position);
- var _loc4_ = _loc3_.length;
- if(_loc4_ < _loc5_)
- {
- _loc5_ = _loc4_;
- _loc7_ = aObjects[_loc2_];
- }
- _loc2_ = _loc2_ + 1;
- }
- return _loc7_;
- }
- }
-