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

  1. function BonusClass()
  2. {
  3.    this.init();
  4. }
  5. delete br;
  6. var br = BonusClass.prototype;
  7. br.init = function()
  8. {
  9.    this.pow = Math.pow;
  10.    this.sqrt = Math.sqrt;
  11.    this.bonuses = [];
  12.    this.bonuses.push({ln:"Bonus_t1",t:$root.Player,f:"hitMe",a:-20,spd:0.02});
  13.    this.bonuses.push({ln:"Bonus_t2",t:$root.Player,f:"extendEnergy",a:20,spd:0.03});
  14.    this.bonuses.push({ln:"Bonus_t3",t:$root.Player,f:"switchAmmo",a:1,spd:0.03});
  15.    this.bonuses.push({ln:"Bonus_t4",t:$root.Player,f:"generateShield",spd:0.03});
  16.    this.bonuses.push({ln:"Bonus_t5",t:$root.Player,f:"generateWingmans",spd:0.03});
  17.    this.gContainer = [{qty:0,t:getTimer()},{qty:0,t:getTimer()},{qty:0,t:getTimer()},{qty:0,t:getTimer()},{qty:0,t:getTimer()}];
  18. };
  19. br.setCourse = function()
  20. {
  21.    var xram = random(($ray + 50) * 2);
  22.    var yram = this.sqrt(this.pow($ray + 50,2) - this.pow(xram - $middle.x,2)) + $middle.y;
  23.    if(random(2) == 0)
  24.    {
  25.       yram -= 2 * (yram - $middle.y);
  26.    }
  27.    return {x:xram,y:yram};
  28. };
  29. br.initialize = function(t)
  30. {
  31.    var bonus = this.bonuses[t];
  32.    var dest = this.setCourse();
  33.    var hd = $root.hd();
  34.    var br = $root.Director.bonusesCon.attachMovie(bonus.ln,bonus.ln + hd,hd,bonus);
  35.    br._gx = $middle.x;
  36.    br._gy = $middle.y;
  37.    br.path = this;
  38.    br.dest = this.setCourse();
  39.    br.onEnterFrame = function()
  40.    {
  41.       this.path.go(this);
  42.    };
  43. };
  44. br.go = function(t)
  45. {
  46.    var is = this.detectHT(t);
  47.    if(!is)
  48.    {
  49.       return undefined;
  50.    }
  51.    var x = t.dest.x;
  52.    var y = t.dest.y;
  53.    with(t)
  54.    {
  55.       var xDis = _x - x;
  56.       var yDis = _y - y;
  57.       _x -= (xDis - 15) * spd;
  58.       _y -= (yDis - 15) * spd;
  59.       _xscale -= (_xscale - 100) * spd;
  60.       _yscale -= (_yscale - 100) * spd;
  61.    }
  62. };
  63. br.detectHT = function(t)
  64. {
  65.    if(t.hitTest($root.Player.tgt.obj) === true)
  66.    {
  67.       t.t[t.f](t.a);
  68.       t.removeMovieClip();
  69.       return false;
  70.    }
  71.    if($root.Director.outArea.hitTest(t._x,t._y,1) === true)
  72.    {
  73.       t.removeMovieClip();
  74.       return false;
  75.    }
  76.    return true;
  77. };
  78. br.addToBG = function(t)
  79. {
  80.    if(this.gContainer[t] == undefined)
  81.    {
  82.       return undefined;
  83.    }
  84.    var bc = $root.Director.bonusesCon;
  85.    if(bc.onEnterFrame == undefined)
  86.    {
  87.       bc.path = this;
  88.       bc.onEnterFrame = function()
  89.       {
  90.          this.path.bonusGenerator();
  91.       };
  92.    }
  93.    this.gContainer[t].qty = this.gContainer[t].qty + 1;
  94. };
  95. br.bonusGenerator = function()
  96. {
  97.    var gc = this.gContainer;
  98.    var l = gc.length;
  99.    while(--l >= 0)
  100.    {
  101.       if(!(gc[l].qty < 1 || getTimer() - gc[l].t < 15000))
  102.       {
  103.          this.initialize(l);
  104.          gc[l].t = getTimer();
  105.          gc[l].qty--;
  106.       }
  107.    }
  108. };
  109.