home *** CD-ROM | disk | FTP | other *** search
- package gamegraphics
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.utils.Timer;
- import game.Game;
- import game.GameObject;
-
- public class TimeBar extends Sprite
- {
-
-
- private var start:int;
-
- private var theGame:Game;
-
- private var timer:Timer;
-
- private var h:int;
-
- private var roundsLeft:int;
-
- private var roundsAtStart:int;
-
- private var bar:Sprite;
-
- private var w:int;
-
- private var obj:GameObject;
-
- public function TimeBar(x:int, y:int, w:int, h:int, timer:Timer, roundsLeft:int, theGame:Game, obj:GameObject)
- {
- super();
- bar = new Sprite();
- bar.x = x;
- bar.y = y;
- bar.graphics.beginFill(657930,0.5);
- bar.graphics.drawRect(0,0,w,h);
- bar.graphics.endFill();
- GameGraphics.sprite.addChild(bar);
- this.theGame = theGame;
- this.timer = timer;
- this.roundsLeft = roundsLeft;
- this.roundsAtStart = roundsLeft;
- this.w = w;
- this.h = h;
- this.obj = obj;
- obj.addEventListener("objectChanged",updateLocation);
- theGame.addEventListener("gameover",destroy);
- timer.addEventListener("timer",update);
- }
-
- private function destroy(event:Event) : void
- {
- timer.removeEventListener("timer",update);
- theGame.removeEventListener("gameover",destroy);
- GameGraphics.sprite.removeChild(bar);
- }
-
- private function update(event:Event) : void
- {
- --roundsLeft;
- if(roundsLeft < 0)
- {
- destroy(null);
- return;
- }
- bar.graphics.clear();
- bar.graphics.beginFill(328965,0.5);
- bar.graphics.drawRect(0,0,w * (roundsLeft / roundsAtStart),h);
- bar.graphics.endFill();
- }
-
- private function updateLocation(event:Event) : void
- {
- bar.x = obj.x;
- bar.y = obj.y - 13;
- }
- }
- }
-