home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / alex_trax.swf / scripts / __Packages / com / neodelight / game / Game.as next >
Encoding:
Text File  |  2007-10-01  |  4.0 KB  |  152 lines

  1. class com.neodelight.game.Game
  2. {
  3.    var id;
  4.    var config;
  5.    var name;
  6.    var title;
  7.    var player;
  8.    var snd;
  9.    var rootFx;
  10.    var stageWidth;
  11.    var stageHeight;
  12.    var hooker;
  13.    var clients;
  14.    var flow;
  15.    var actLevel;
  16.    static var PAUSE_ENGINE = 1;
  17.    static var PAUSE_USER = 2;
  18.    function Game(config)
  19.    {
  20.       com.neodelight.flanix.Kernel.init();
  21.       this.id = "game" + com.neodelight.std.Unique.getId();
  22.       if(config)
  23.       {
  24.          this.config = config;
  25.       }
  26.       else
  27.       {
  28.          this.config = com.neodelight.std.Blueprint.getBlueprint("game");
  29.          if(!this.config)
  30.          {
  31.             trace("!!!blueprint \"game\" not found");
  32.          }
  33.       }
  34.       _global.game = this;
  35.       this.name = this.config.gameName;
  36.       this.title = this.config.gameTitle;
  37.       com.neodelight.std.ClassLib.init();
  38.       if(com.neodelight.std.Blueprint.isBlueprint("player"))
  39.       {
  40.          var _loc6_ = com.neodelight.std.Blueprint.getBlueprint("player");
  41.          if(!_loc6_)
  42.          {
  43.             trace("!!!blueprint \"player\" not found");
  44.          }
  45.          var _loc5_ = com.neodelight.std.ClassLib.getClass("Player");
  46.          if(_loc5_ == undefined)
  47.          {
  48.             trace("!!!class \"Player\" not found in ClassLib");
  49.          }
  50.          else
  51.          {
  52.             var _loc7_ = new _loc5_(_loc6_);
  53.             this.player = _global.player;
  54.          }
  55.       }
  56.       if(this.config.gameHighscores)
  57.       {
  58.          _global.highscores = new com.neodelight.game.Highscores(this.name,this.config.gameHighscoresKey0,this.config.gameHighscoresKey1);
  59.       }
  60.       _global.score = new com.neodelight.game.Score(this.config.gameScoreTypes);
  61.       this.snd = new com.neodelight.std.XSound();
  62.       _global.snd = this.snd;
  63.       _root.snd = this.snd;
  64.       this.rootFx = new com.neodelight.std.ColorFader(_root);
  65.       if(System.capabilities.playerType == "external")
  66.       {
  67.          this.stageWidth = 550;
  68.          this.stageHeight = 400;
  69.       }
  70.       else
  71.       {
  72.          this.stageWidth = Stage.width;
  73.          this.stageHeight = Stage.height;
  74.       }
  75.       if(this.config.gameTimer)
  76.       {
  77.          _global.timer = new com.neodelight.std.Timer(this.config);
  78.       }
  79.       else
  80.       {
  81.          _global.dt = 1;
  82.       }
  83.       this.hooker = _root.createEmptyMovieClip(com.neodelight.std.Unique.getKey(),_root.getNextHighestDepth());
  84.       this.hooker.clients = new Object();
  85.       this.hooker.onEnterFrame = function()
  86.       {
  87.          if(_global.paused)
  88.          {
  89.             return undefined;
  90.          }
  91.          for(var _loc3_ in this.clients)
  92.          {
  93.             this.clients[_loc3_].move();
  94.          }
  95.       };
  96.       com.neodelight.std.Inputs.init();
  97.       this.flow = new com.neodelight.std.Flow();
  98.       this.reset();
  99.       _global.bin.lvl = function(n)
  100.       {
  101.          _global.game.initLevel(n);
  102.       };
  103.    }
  104.    function reset()
  105.    {
  106.       _global.highscores.init();
  107.       _global.score.reset();
  108.       this.hooker.clients = new Object();
  109.       this.actLevel = 0;
  110.    }
  111.    function initLevel(id)
  112.    {
  113.       trace("initLevel(id:" + id + ")");
  114.       if(id != undefined)
  115.       {
  116.          this.actLevel = id;
  117.       }
  118.       delete this.hooker.clients;
  119.       this.hooker.clients = new Object();
  120.       _global.score.initLevel();
  121.    }
  122.    function initGame()
  123.    {
  124.       this.reset();
  125.    }
  126.    function hookIn(o)
  127.    {
  128.       var _loc2_ = !o.id ? com.neodelight.std.Unique.getKey() : o.id;
  129.       if(!_loc2_)
  130.       {
  131.          trace("!!!can\'t assign id to object:" + o);
  132.       }
  133.       trace("o:" + o + ",o.id:" + o.id);
  134.       if(this.hooker.clients[_loc2_])
  135.       {
  136.          trace("!id " + _loc2_ + " already exists in hook");
  137.          return "";
  138.       }
  139.       this.hooker.clients[_loc2_] = o;
  140.       return _loc2_;
  141.    }
  142.    function hookOut(o)
  143.    {
  144.       trace("o:" + o + ",o.id:" + o.id);
  145.       delete this.hooker.clients[o.id];
  146.    }
  147.    function pause(stat, mode)
  148.    {
  149.       _global.paused = stat;
  150.    }
  151. }
  152.