home *** CD-ROM | disk | FTP | other *** search
- Timer = function(mc)
- {
- this.mc = mc;
- this.mc.obj = this;
- GAME.addListener(this);
- GAME.threeGameFrames.addListener(this);
- };
- t = Timer.prototype;
- t.mc = false;
- t.id = "Timer";
- t.timeRemaining = 0;
- t.timeElapsed = 0;
- t.totalTime = 0;
- t.lastTime = 0;
- t.enabled = false;
- t.aniCurTime = 0;
- t.aniDestTime = 0;
- t.setTime = function(time)
- {
- this.totalTime = time;
- this.timeRemaining = this.totalTime;
- this.timeElapsed = 0;
- this.timePer = 1;
- this.lastTime = GAME.gameTimeElapsed;
- };
- t.start = function(time)
- {
- if(time != undefined)
- {
- this.setTime(time);
- }
- this.enabled = true;
- };
- t.stop = function()
- {
- this.reset();
- };
- t.reset = function()
- {
- this.enabled = false;
- this.totalTime = 0;
- this.timeRemaining = this.totalTime;
- this.timeElapsed = 0;
- this.lastTime = 0;
- };
- t.pause = function()
- {
- this.enabled = false;
- };
- t.unpause = function()
- {
- this.enabled = true;
- };
- t.timerLoop = function()
- {
- var _loc2_ = GAME.gameTimeElapsed;
- var _loc3_ = _loc2_ - this.lastTime;
- this.lastTime = _loc2_;
- this.timeElapsed += _loc3_;
- this.timeRemaining = this.totalTime - this.timeElapsed;
- this.timePer = this.timeRemaining / this.totalTime;
- this.draw(this.timeRemaining,this.timePer);
- if(this.timeRemaining < 6)
- {
- GAME.interface_mc.final_countdown_mc.showNum(Math.round(this.timeRemaining));
- if(this.timeRemaining < 0)
- {
- this.mc.gotoAndPlay("time_up");
- this.timeRemaining = 0;
- GAME.timeOut();
- }
- }
- };
- t.startDrawLoop = function(startAt, dest)
- {
- this.aniCurTime = startAt;
- this.aniDestTime = dest;
- if(isNaN(this.aniCurTime) || this.aniCurTime == undefined)
- {
- this.aniCurTime = 0;
- }
- this.mc.onEnterFrame = function()
- {
- this.obj.drawLoop();
- };
- };
- t.stopLoop = function()
- {
- delete this.mc.onEnterFrame;
- };
- t.drawLoop = function()
- {
- this.aniCurTime += (this.aniDestTime - this.aniCurTime) * 0.1;
- if(Math.round(this.aniCurTime) == this.aniDestTime)
- {
- this.aniCurTime = this.aniDestTime;
- this.stopLoop();
- }
- var _loc2_ = this.aniCurTime / this.totalTime;
- this.draw(Math.round(this.aniCurTime),_loc2_);
- };
- t.draw = function(time, per)
- {
- var _loc3_ = Math.floor(time / 60);
- var _loc2_ = Math.floor(time) % 60;
- if(_loc3_ < 0)
- {
- _loc3_ = 0;
- }
- if(_loc2_ < 10)
- {
- if(_loc2_ < 0)
- {
- _loc2_ = "00";
- }
- else
- {
- _loc2_ = "0" + _loc2_;
- }
- }
- this.mc.mins_text = _loc3_;
- this.mc.secs_text = _loc2_;
- this.mc.elapsed_out = Math.floor(this.timeElapsed);
- this.mc.backing.showPer(per,true);
- };
- t.addTimeToScore = function()
- {
- var _loc2_ = Math.round(this.timeRemaining) * GAME.parameters.points.timerSecond;
- GAME.adjustScore(_loc2_,this);
- };
- t.onLevelStart = function()
- {
- this.start();
- };
- t.onLevelComplete = function()
- {
- this.pause();
- this.addTimeToScore();
- this.enabled = false;
- this.timeElapsed = 0;
- this.lastTime = 0;
- this.startDrawLoop(this.timeRemaining,0);
- this.timeRemaining = 0;
- };
- t.onLevelIncomplete = function()
- {
- this.pause();
- };
- t.onThreeGameFrames = function()
- {
- this.timerLoop();
- };
- t.onLevelEnter = function(level)
- {
- this.setTime(level.timeLimit);
- this.startDrawLoop(0,this.totalTime);
- };
-