home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / 2Deep.swf / scripts / frame_94 / DoAction_7.as < prev    next >
Encoding:
Text File  |  2005-08-08  |  5.8 KB  |  232 lines

  1. function PlayerClass()
  2. {
  3.    this.init();
  4. }
  5. delete pr;
  6. var pr = PlayerClass.prototype;
  7. pr.init = function()
  8. {
  9.    this.min = Math.min;
  10.    this.linkage = "PlayerBox";
  11.    this.mc = "player_mc";
  12.    this.bulletLinkage = "Player_bullet";
  13.    this.shieldLN = "Player_shield";
  14.    this.wingmanLN = "Player_wingman";
  15.    this.conf = {bulletID:0,spd:0.06,eCurr:100,eMax:100};
  16.    $root.energy = this.conf.eCurr;
  17.    this.bullets = [];
  18.    this.bullets.push({ln:"Player_nBullet",spd:0.09,pwr:10});
  19.    this.bullets.push({ln:"Player_dblBullet",spd:0.07,pwr:15});
  20.    this.bullets[900] = {ln:"Player_wmbullet",spd:0.08,pwr:2};
  21.    this.abs = Math.abs;
  22.    this.pow = Math.pow;
  23.    this.sqrt = Math.sqrt;
  24.    this.sin = Math.sin;
  25.    this.asin = Math.asin;
  26.    this.cos = Math.cos;
  27.    this.pi = 3.141592653589793;
  28.    this.temp = 0;
  29. };
  30. pr.place = function()
  31. {
  32.    this.tgt = $root.attachMovie(this.linkage,this.mc,$root.hd(),{_x:$middle.x,_y:$middle.y});
  33.    this.tgt.path = this;
  34.    var o = this.keyObj = {path:this};
  35.    o.fire = true;
  36.    o.onKeyDown = function()
  37.    {
  38.       if($root.Director.currEmsQty < 1)
  39.       {
  40.          return undefined;
  41.       }
  42.       if(Key.isDown(32) && this.fire === true)
  43.       {
  44.          this.path.shoot();
  45.          this.fire = false;
  46.       }
  47.    };
  48.    o.onKeyUp = function()
  49.    {
  50.       if(Key.getCode() == 32)
  51.       {
  52.          this.fire = true;
  53.       }
  54.    };
  55.    Key.addListener(o);
  56.    this.tgt.onEnterFrame = function()
  57.    {
  58.       this.path.updPosition();
  59.    };
  60. };
  61. pr.remove = function()
  62. {
  63.    this.tgt.removeMovieClip();
  64. };
  65. pr.updPosition = function()
  66. {
  67.    var ecr = $root.Director.enemiesCon;
  68.    if(this.tgt.h1.hitTest(ecr) == true || this.tgt.h2.hitTest(ecr) == true || this.tgt.h3.hitTest(ecr) == true || this.tgt.h4.hitTest(ecr) == true || this.tgt.h5.hitTest(ecr) == true)
  69.    {
  70.       for(var e in ecr)
  71.       {
  72.          if(this.tgt.obj.hitTest(ecr[e]) == true)
  73.          {
  74.             this.hitMe(ecr[e].power);
  75.             $root.Director.destroyEnemy(ecr[e]);
  76.             ecr[e].removeMovieClip();
  77.          }
  78.       }
  79.    }
  80.    if(Key.isDown(37))
  81.    {
  82.       this.plrAngle += 6;
  83.    }
  84.    if(Key.isDown(39))
  85.    {
  86.       this.plrAngle -= 6;
  87.    }
  88.    this.plrAngle2 -= (this.plrAngle2 - this.plrAngle) * 0.1;
  89.    this.tgt._rotation = this.plrAngle2 % 360;
  90. };
  91. pr.shoot = function(coor)
  92. {
  93.    var hd = $root.hd();
  94.    var o = this.bullets[this.conf.bulletID];
  95.    var ln = o.ln;
  96.    o._x = this.tgt.obj._gx + coor.x;
  97.    o._y = this.tgt.obj._gy + coor.y;
  98.    o._rotation = this.tgt._rotation;
  99.    var br = $root.attachMovie(ln,hd + "bullet",hd,o);
  100.    br.onEnterFrame = this.shootOEF;
  101. };
  102. pr.shootOEF = function()
  103. {
  104.    var ecr = $root.Director.enemiesCon;
  105.    if(this.hitTest(ecr) == true)
  106.    {
  107.       for(var e in ecr)
  108.       {
  109.          if(this.hitTest(ecr[e]) == true)
  110.          {
  111.             if(ecr[e]._xscale > 25)
  112.             {
  113.                $root.Director.hitEnemy(ecr[e],this.pwr);
  114.                this.removeMovieClip();
  115.             }
  116.          }
  117.       }
  118.    }
  119.    var xDis = this._gx - $middle.x;
  120.    var yDis = this._gy - $middle.y;
  121.    if(Math.abs(xDis) < 1 && Math.abs(yDis) < 1)
  122.    {
  123.       this.removeMovieClip();
  124.    }
  125.    this._x -= xDis * this.spd;
  126.    this._y -= yDis * this.spd;
  127.    this._xscale -= 20 * this.spd;
  128.    this._yscale -= 20 * this.spd;
  129.    this._alpha -= 20 * this.spd;
  130.    updateAfterEvent();
  131. };
  132. pr.hitMe = function(p)
  133. {
  134.    this.conf.eCurr -= p;
  135.    this.conf.eCurr = this.min(this.conf.eCurr,this.conf.eMax);
  136.    if(this.conf.eCurr <= 0)
  137.    {
  138.       this.killMe();
  139.       $root.energy = 0;
  140.       return undefined;
  141.    }
  142.    if(this.conf.eCurr < 65)
  143.    {
  144.       $root.Bonus.addToBG(0);
  145.    }
  146.    if(p > 0 && this.bonusWingman != undefined)
  147.    {
  148.       this.kill_wingman();
  149.    }
  150.    if(p > 0 && this.conf.bulletID > 0)
  151.    {
  152.       this.conf.bulletID--;
  153.    }
  154.    $root.energy = this.conf.eCurr;
  155. };
  156. pr.killMe = function()
  157. {
  158.    if(this.bonusWingman != undefined)
  159.    {
  160.       this.kill_wingman();
  161.    }
  162.    var hd = $root.hD();
  163.    var exr = $root.attachMovie("plr_explosion","plr_explosion" + hd,hd,{_xscale:70,_yscale:70});
  164.    exr._gx = this.tgt.obj._gx;
  165.    exr._gy = this.tgt.obj._gy;
  166.    Key.removeListener(this.keyObj);
  167.    delete this.keyObj;
  168.    _root.scr = $root.score;
  169.    $root.Director.enemiesCon.removeMovieClip();
  170.    $root.Director.bonusesCon.removeMovieClip();
  171.    this.tgt.removeMovieClip();
  172.    gotoAndStop(95);
  173. };
  174. pr.extendEnergy = function(v)
  175. {
  176.    this.conf.eMax += v;
  177. };
  178. pr.switchAmmo = function(t)
  179. {
  180.    var cb = this.conf.bulletID;
  181.    if(this.bullets[++cb] == undefined)
  182.    {
  183.       return undefined;
  184.    }
  185.    this.conf.bulletID = this.conf.bulletID + 1;
  186. };
  187. pr.generateShield = function()
  188. {
  189.    this.tgt.obj[this.shieldLN].removeMovieClip();
  190.    this.bonusShield = this.tgt.obj.attachMovie(this.shieldLN,this.shieldLN,this.tgt.obj.hD(),{init:getTimer(),dur:20000,hits:3,path:this});
  191.    this.bonusShield.onEnterFrame = this.shieldOEF;
  192. };
  193. pr.destroyShield = function()
  194. {
  195.    this.bonusShield.removeMovieClip();
  196. };
  197. pr.shieldOEF = function()
  198. {
  199.    var ecr = $root.Director.enemiesCon;
  200.    if(this.hitTest(ecr) == true)
  201.    {
  202.       for(var e in ecr)
  203.       {
  204.          if(this.hitTest(ecr[e]) == true)
  205.          {
  206.             $root.Director.destroyEnemy(ecr[e]);
  207.             this.hits--;
  208.          }
  209.       }
  210.    }
  211.    if(this.hits <= 0)
  212.    {
  213.       this.path.destroyShield();
  214.    }
  215.    if(getTimer() - this.init > this.dur)
  216.    {
  217.       this.path.destroyShield();
  218.    }
  219. };
  220. pr.generateWingmans = function()
  221. {
  222.    this.extendEnergy(20);
  223.    this.hitMe(-20);
  224.    this.bonusWingman = this.tgt.attachMovie(this.wingmanLN,this.wingmanLN,this.tgt.hd(),{_y:230,path:this,hits:3});
  225.    this.conf.bulletID = 900;
  226. };
  227. pr.kill_wingman = function()
  228. {
  229.    this.conf.bulletID = 0;
  230.    this.bonusWingman.removeMovieClip();
  231. };
  232.