home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / xwung.swf / scripts / com / lofiminds / gm / GameApplication.as < prev    next >
Encoding:
Text File  |  2008-09-03  |  2.3 KB  |  82 lines

  1. package com.lofiminds.gm
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.events.Event;
  5.    import flash.events.KeyboardEvent;
  6.    import flash.events.MouseEvent;
  7.    import flash.media.Sound;
  8.    import flash.media.SoundTransform;
  9.    import flash.utils.getTimer;
  10.    
  11.    public class GameApplication extends Sprite
  12.    {
  13.        
  14.       
  15.       public var fpsCount:int = 0;
  16.       
  17.       public var soundFxTransform:SoundTransform;
  18.       
  19.       public var showFps:Boolean = false;
  20.       
  21.       public var showCollisionRects:Boolean = false;
  22.       
  23.       private var fpsTime:int = 0;
  24.       
  25.       private var fpsFrames:int = 0;
  26.       
  27.       public function GameApplication()
  28.       {
  29.          super();
  30.          addEventListener(Event.ENTER_FRAME,run);
  31.          addEventListener(Event.ADDED_TO_STAGE,onAddToStage);
  32.          GameContext.app = this;
  33.       }
  34.       
  35.       private function onAddToStage(param1:Event) : void
  36.       {
  37.          stage.addEventListener(KeyboardEvent.KEY_DOWN,GameInput.keyDownHandler);
  38.          stage.addEventListener(KeyboardEvent.KEY_UP,GameInput.keyUpHandler);
  39.          stage.addEventListener(MouseEvent.MOUSE_MOVE,GameInput.mouseMoveHandler);
  40.          stage.addEventListener(MouseEvent.MOUSE_DOWN,GameInput.mouseDownHandler);
  41.          stage.addEventListener(MouseEvent.MOUSE_UP,GameInput.mouseUpHandler);
  42.          var _loc2_:GameRoom = createRoom();
  43.          addChild(_loc2_);
  44.          _loc2_.init();
  45.          GameContext.room = _loc2_;
  46.          this.onInit();
  47.       }
  48.       
  49.       public function playSound(param1:Sound) : void
  50.       {
  51.          param1.play(0,0,this.soundFxTransform);
  52.       }
  53.       
  54.       public function onInit() : void
  55.       {
  56.       }
  57.       
  58.       private function run(param1:Event) : void
  59.       {
  60.          Instances.updateGameObjects();
  61.          Collisions.update();
  62.          if(GameContext.room != null)
  63.          {
  64.             GameContext.room.repaint();
  65.          }
  66.          ++fpsFrames;
  67.          var _loc2_:int = getTimer();
  68.          if(_loc2_ - fpsTime > 1000)
  69.          {
  70.             fpsCount = fpsFrames / ((_loc2_ - fpsTime) / 1000);
  71.             fpsFrames = 0;
  72.             fpsTime = _loc2_;
  73.          }
  74.       }
  75.       
  76.       public function createRoom() : GameRoom
  77.       {
  78.          return new GameRoom();
  79.       }
  80.    }
  81. }
  82.