home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Diversos / beaverdive.swf / scripts / frame_1 / DoAction_3.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  2.9 KB  |  120 lines

  1. _global.Timer = function(onChangeFunction, changeInterval, firstTick, clip)
  2. {
  3.    this.initTime = getTimer();
  4.    this.initClip(clip);
  5.    this.killTime = null;
  6.    this.milissec = 0;
  7.    this.nextChange = 0;
  8.    this.changeInterval = changeInterval;
  9.    this.onChangeFunction = onChangeFunction;
  10.    if(firstTick == undefined)
  11.    {
  12.       firstTick = false;
  13.    }
  14.    this.firstTick = firstTick;
  15.    this.dead = false;
  16. };
  17. Timer.prototype.tick = function()
  18. {
  19.    this.milissec = getTimer() - this.initTime;
  20. };
  21. Timer.prototype.updateTime = function(newTime)
  22. {
  23.    this.changeInterval = newTime;
  24. };
  25. Timer.prototype.initClip = function(clip)
  26. {
  27.    var _loc3_ = randomInt(0,1000000);
  28.    var _loc4_ = "clock" + _loc3_;
  29.    if(clip == undefined)
  30.    {
  31.       clip = "timer";
  32.    }
  33.    _root.attachMovie(clip,_loc4_,_loc3_);
  34.    this.clip = _root[_loc4_];
  35.    this.clip.obj = this;
  36.    this.clip.onEnterFrame = function()
  37.    {
  38.       this.obj.enterFrame();
  39.    };
  40. };
  41. Timer.prototype.addKill = function(num)
  42. {
  43.    this.killTime = num;
  44. };
  45. Timer.prototype.kill = function()
  46. {
  47.    if(this.killTime == null)
  48.    {
  49.       return undefined;
  50.    }
  51.    if(this.milissec >= this.killTime)
  52.    {
  53.       this.clip.removeMovieClip();
  54.       this.dead = true;
  55.       false;
  56.    }
  57. };
  58. Timer.prototype.killNow = function()
  59. {
  60.    this.clip.removeMovieClip();
  61.    this.dead = true;
  62.    false;
  63. };
  64. Timer.prototype.change = function()
  65. {
  66.    if(this.changeInterval == undefined)
  67.    {
  68.       this.changeInterval = 1 * SEC;
  69.    }
  70.    if(this.milissec >= this.nextChange || this.nextChange == undefined)
  71.    {
  72.       if(this.nextChange == 0 && this.firstTick == false)
  73.       {
  74.          this.nextChange = this.milissec + this.changeInterval;
  75.          return false;
  76.       }
  77.       this.nextChange = this.milissec + this.changeInterval;
  78.       return true;
  79.    }
  80.    return false;
  81. };
  82. Timer.prototype.enterFrame = function()
  83. {
  84.    this.tick();
  85.    this.kill();
  86.    if(this.change())
  87.    {
  88.       this.onChangeFunction();
  89.    }
  90. };
  91. enemyCounter = 0;
  92. _global.releaseEnemy = function()
  93. {
  94.    var _loc5_ = random(3);
  95.    _root.enemyGenerator["enemy" + _loc5_].duplicateMovieClip("e" + enemyCounter,enemyCounter);
  96.    var _loc3_ = random(2);
  97.    if(_loc3_ > 0)
  98.    {
  99.       _loc3_ = -1;
  100.    }
  101.    else
  102.    {
  103.       _loc3_ = 1;
  104.    }
  105.    if(_loc3_ < 0)
  106.    {
  107.       _root.enemyGenerator["e" + enemyCounter]._x = 600 + _root.enemyGenerator["e" + enemyCounter]._width;
  108.    }
  109.    else
  110.    {
  111.       _root.enemyGenerator["e" + enemyCounter]._x = - _root.enemyGenerator["e" + enemyCounter]._width;
  112.    }
  113.    _root.enemyGenerator["e" + enemyCounter].dir = _loc3_;
  114.    _root.enemyGenerator["e" + enemyCounter]._xscale *= _loc3_;
  115.    _root.enemyGenerator["e" + enemyCounter].speed = _loc3_ * randomInt(3,5);
  116.    var _loc4_ = random(4) + 1;
  117.    _root.enemyGenerator["e" + enemyCounter]._y = _root["spot" + _loc4_]._y;
  118.    enemyCounter++;
  119. };
  120.