home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Jumper.swf / scripts / gamegraphics / TimeBar.as < prev   
Encoding:
Text File  |  2008-09-05  |  2.1 KB  |  81 lines

  1. package gamegraphics
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.events.Event;
  5.    import flash.utils.Timer;
  6.    import game.Game;
  7.    import game.GameObject;
  8.    
  9.    public class TimeBar extends Sprite
  10.    {
  11.        
  12.       
  13.       private var start:int;
  14.       
  15.       private var theGame:Game;
  16.       
  17.       private var timer:Timer;
  18.       
  19.       private var h:int;
  20.       
  21.       private var roundsLeft:int;
  22.       
  23.       private var roundsAtStart:int;
  24.       
  25.       private var bar:Sprite;
  26.       
  27.       private var w:int;
  28.       
  29.       private var obj:GameObject;
  30.       
  31.       public function TimeBar(x:int, y:int, w:int, h:int, timer:Timer, roundsLeft:int, theGame:Game, obj:GameObject)
  32.       {
  33.          super();
  34.          bar = new Sprite();
  35.          bar.x = x;
  36.          bar.y = y;
  37.          bar.graphics.beginFill(657930,0.5);
  38.          bar.graphics.drawRect(0,0,w,h);
  39.          bar.graphics.endFill();
  40.          GameGraphics.sprite.addChild(bar);
  41.          this.theGame = theGame;
  42.          this.timer = timer;
  43.          this.roundsLeft = roundsLeft;
  44.          this.roundsAtStart = roundsLeft;
  45.          this.w = w;
  46.          this.h = h;
  47.          this.obj = obj;
  48.          obj.addEventListener("objectChanged",updateLocation);
  49.          theGame.addEventListener("gameover",destroy);
  50.          timer.addEventListener("timer",update);
  51.       }
  52.       
  53.       private function destroy(event:Event) : void
  54.       {
  55.          timer.removeEventListener("timer",update);
  56.          theGame.removeEventListener("gameover",destroy);
  57.          GameGraphics.sprite.removeChild(bar);
  58.       }
  59.       
  60.       private function update(event:Event) : void
  61.       {
  62.          --roundsLeft;
  63.          if(roundsLeft < 0)
  64.          {
  65.             destroy(null);
  66.             return;
  67.          }
  68.          bar.graphics.clear();
  69.          bar.graphics.beginFill(328965,0.5);
  70.          bar.graphics.drawRect(0,0,w * (roundsLeft / roundsAtStart),h);
  71.          bar.graphics.endFill();
  72.       }
  73.       
  74.       private function updateLocation(event:Event) : void
  75.       {
  76.          bar.x = obj.x;
  77.          bar.y = obj.y - 13;
  78.       }
  79.    }
  80. }
  81.