home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / eolica.swf / scripts / frame_18 / DoAction.as
Encoding:
Text File  |  2005-07-26  |  3.4 KB  |  158 lines

  1. Timer = function(mc)
  2. {
  3.    this.mc = mc;
  4.    this.mc.obj = this;
  5.    GAME.addListener(this);
  6.    GAME.threeGameFrames.addListener(this);
  7. };
  8. t = Timer.prototype;
  9. t.mc = false;
  10. t.id = "Timer";
  11. t.timeRemaining = 0;
  12. t.timeElapsed = 0;
  13. t.totalTime = 0;
  14. t.lastTime = 0;
  15. t.enabled = false;
  16. t.aniCurTime = 0;
  17. t.aniDestTime = 0;
  18. t.setTime = function(time)
  19. {
  20.    this.totalTime = time;
  21.    this.timeRemaining = this.totalTime;
  22.    this.timeElapsed = 0;
  23.    this.timePer = 1;
  24.    this.lastTime = GAME.gameTimeElapsed;
  25. };
  26. t.start = function(time)
  27. {
  28.    if(time != undefined)
  29.    {
  30.       this.setTime(time);
  31.    }
  32.    this.enabled = true;
  33. };
  34. t.stop = function()
  35. {
  36.    this.reset();
  37. };
  38. t.reset = function()
  39. {
  40.    this.enabled = false;
  41.    this.totalTime = 0;
  42.    this.timeRemaining = this.totalTime;
  43.    this.timeElapsed = 0;
  44.    this.lastTime = 0;
  45. };
  46. t.pause = function()
  47. {
  48.    this.enabled = false;
  49. };
  50. t.unpause = function()
  51. {
  52.    this.enabled = true;
  53. };
  54. t.timerLoop = function()
  55. {
  56.    var _loc2_ = GAME.gameTimeElapsed;
  57.    var _loc3_ = _loc2_ - this.lastTime;
  58.    this.lastTime = _loc2_;
  59.    this.timeElapsed += _loc3_;
  60.    this.timeRemaining = this.totalTime - this.timeElapsed;
  61.    this.timePer = this.timeRemaining / this.totalTime;
  62.    this.draw(this.timeRemaining,this.timePer);
  63.    if(this.timeRemaining < 6)
  64.    {
  65.       GAME.interface_mc.final_countdown_mc.showNum(Math.round(this.timeRemaining));
  66.       if(this.timeRemaining < 0)
  67.       {
  68.          this.mc.gotoAndPlay("time_up");
  69.          this.timeRemaining = 0;
  70.          GAME.timeOut();
  71.       }
  72.    }
  73. };
  74. t.startDrawLoop = function(startAt, dest)
  75. {
  76.    this.aniCurTime = startAt;
  77.    this.aniDestTime = dest;
  78.    if(isNaN(this.aniCurTime) || this.aniCurTime == undefined)
  79.    {
  80.       this.aniCurTime = 0;
  81.    }
  82.    this.mc.onEnterFrame = function()
  83.    {
  84.       this.obj.drawLoop();
  85.    };
  86. };
  87. t.stopLoop = function()
  88. {
  89.    delete this.mc.onEnterFrame;
  90. };
  91. t.drawLoop = function()
  92. {
  93.    this.aniCurTime += (this.aniDestTime - this.aniCurTime) * 0.1;
  94.    if(Math.round(this.aniCurTime) == this.aniDestTime)
  95.    {
  96.       this.aniCurTime = this.aniDestTime;
  97.       this.stopLoop();
  98.    }
  99.    var _loc2_ = this.aniCurTime / this.totalTime;
  100.    this.draw(Math.round(this.aniCurTime),_loc2_);
  101. };
  102. t.draw = function(time, per)
  103. {
  104.    var _loc3_ = Math.floor(time / 60);
  105.    var _loc2_ = Math.floor(time) % 60;
  106.    if(_loc3_ < 0)
  107.    {
  108.       _loc3_ = 0;
  109.    }
  110.    if(_loc2_ < 10)
  111.    {
  112.       if(_loc2_ < 0)
  113.       {
  114.          _loc2_ = "00";
  115.       }
  116.       else
  117.       {
  118.          _loc2_ = "0" + _loc2_;
  119.       }
  120.    }
  121.    this.mc.mins_text = _loc3_;
  122.    this.mc.secs_text = _loc2_;
  123.    this.mc.elapsed_out = Math.floor(this.timeElapsed);
  124.    this.mc.backing.showPer(per,true);
  125. };
  126. t.addTimeToScore = function()
  127. {
  128.    var _loc2_ = Math.round(this.timeRemaining) * GAME.parameters.points.timerSecond;
  129.    GAME.adjustScore(_loc2_,this);
  130. };
  131. t.onLevelStart = function()
  132. {
  133.    this.start();
  134. };
  135. t.onLevelComplete = function()
  136. {
  137.    this.pause();
  138.    this.addTimeToScore();
  139.    this.enabled = false;
  140.    this.timeElapsed = 0;
  141.    this.lastTime = 0;
  142.    this.startDrawLoop(this.timeRemaining,0);
  143.    this.timeRemaining = 0;
  144. };
  145. t.onLevelIncomplete = function()
  146. {
  147.    this.pause();
  148. };
  149. t.onThreeGameFrames = function()
  150. {
  151.    this.timerLoop();
  152. };
  153. t.onLevelEnter = function(level)
  154. {
  155.    this.setTime(level.timeLimit);
  156.    this.startDrawLoop(0,this.totalTime);
  157. };
  158.