home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Acao / germ_roundup.swf / scripts / __Packages / MaggieWorld.as < prev    next >
Encoding:
Text File  |  2007-03-20  |  8.4 KB  |  297 lines

  1. class MaggieWorld
  2. {
  3.    var __LOWQUAL;
  4.    var score;
  5.    var oPlayer;
  6.    static var target;
  7.    var nFullTime = 125;
  8.    var cTime = -10;
  9.    var startTime = -10;
  10.    var nTimeDec = 12.5;
  11.    var nLowerTimeLimit = 45;
  12.    var nDist = 10000;
  13.    var germReq = 10;
  14.    var timeBonus = 5000;
  15.    var playerOffset = 100;
  16.    var nPanic = 0.065;
  17.    var __MIN_BENCHMARK = 600;
  18.    function MaggieWorld(loc)
  19.    {
  20.       var _loc1_ = this;
  21.       MaggieWorld.target = _loc1_;
  22.       _loc1_.location = loc;
  23.       _loc1_.oBuildings = new BuildingHandler(_loc1_.location.mcBuildingHolder);
  24.       _loc1_.oBuildings.oWorld = _loc1_;
  25.       _loc1_.oCitizens = new CitizenHandler(_loc1_.location.mcCitizens);
  26.       _loc1_.oCitizens.oBuildings = _loc1_.oBuildings;
  27.       _loc1_.oGerms = new GermHandler(_loc1_.location.mcGermHolder);
  28.       _loc1_.oBuildings.oGerms = _loc1_.oGerms;
  29.       _loc1_.oPlayer = _loc1_.location.mcPlayer;
  30.       _loc1_.oPlayer.setBuilding(_loc1_.oBuildings,_loc1_.oCitizens,_loc1_.oGerms);
  31.       _loc1_.oPlayer.setShadow(_loc1_.location.mcShadow);
  32.       _loc1_.oPlayer.oWorld = _loc1_;
  33.       _loc1_.oBundle = _loc1_.location.mcBundle;
  34.       _loc1_.mcDraw = loc.mcDraw;
  35.       _loc1_.oBundle.init(_loc1_.oPlayer,_loc1_.mcDraw);
  36.       smashing.Menu.watchProp(_loc1_,"lives","text");
  37.       smashing.Menu.watchProp(_loc1_,"level","text");
  38.       smashing.Menu.watchProp(_loc1_,"score","text");
  39.       smashing.Menu.watchProp(_loc1_,"cTimeRatio","funkyMeter");
  40.       smashing.Menu.watchProp(_loc1_,"nDistRatio","funkyMeter");
  41.       _loc1_.lives = 3;
  42.       _loc1_.level = 1;
  43.       _loc1_.score = 0;
  44.       _loc1_.cTimeRatio = 0;
  45.       _loc1_.nDistRatio = 0;
  46.       _loc1_.__LOWQUAL = false;
  47.       if(_global.maggiePerformance.processor < _loc1_.__MIN_BENCHMARK)
  48.       {
  49.          _loc1_.__LOWQUAL = true;
  50.       }
  51.    }
  52.    function onEnter()
  53.    {
  54.    }
  55.    function onExit()
  56.    {
  57.    }
  58.    function onPlay()
  59.    {
  60.       if(this.__LOWQUAL)
  61.       {
  62.          _quality = "MEDIUM";
  63.       }
  64.       else
  65.       {
  66.          _quality = "HIGH";
  67.       }
  68.    }
  69.    function onPause()
  70.    {
  71.       _quality = "HIGH";
  72.    }
  73.    function update(nElapsed)
  74.    {
  75.       var _loc1_ = this;
  76.       var _loc2_ = nElapsed;
  77.       _loc1_.cTime += _loc2_;
  78.       _loc1_.cTimeRatio = _loc1_.cTime / _loc1_.nTime;
  79.       _loc1_.mcDraw.clear();
  80.       _loc1_.oCitizens.setRatio(_loc1_.cTime / _loc1_.nTime);
  81.       _loc1_.oCitizens.update(_loc2_);
  82.       _loc1_.oPlayer.update(_loc2_);
  83.       _loc1_.oBundle.update(_loc2_);
  84.       _loc1_.moveView(_loc2_);
  85.       _loc1_.nDistRatio = smashing.Viewport.x / _loc1_.nDist;
  86.       _loc1_.endCheck();
  87.       _loc1_.oPlayer.render();
  88.       _loc1_.oBundle.render();
  89.       _loc1_.oGerms.update(_loc2_);
  90.       _loc1_.oBuildings.render();
  91.       var _loc3_ = _loc1_.nDistRatio - _loc1_.cTimeRatio;
  92.       _root.nDebug1 = _loc1_.oBuildings.nTotalGerms;
  93.       if(_loc3_ <= _loc1_.nPanic && _loc1_.howFar > 800)
  94.       {
  95.          smashing.Menu.target.funkyMeter.cTimeRatioCap.gotoAndStop("panic");
  96.       }
  97.       else
  98.       {
  99.          smashing.Menu.target.funkyMeter.cTimeRatioCap.gotoAndStop("normal");
  100.       }
  101.       updateAfterEvent();
  102.    }
  103.    function newGame()
  104.    {
  105.       this.startLevel();
  106.       this.score = 0;
  107.    }
  108.    function startLevel()
  109.    {
  110.       var _loc1_ = this;
  111.       var _loc2_ = _global;
  112.       _loc1_.location.bg.gotoAndStop((_loc1_.level - 1) % 3 + 1);
  113.       _loc1_.location.street.gotoAndStop((_loc1_.level - 1) % 3 + 1);
  114.       _loc1_.howFar = 0;
  115.       smashing.Viewport.reset();
  116.       _loc1_.oBuildings.reset();
  117.       _loc1_.oPlayer.reset();
  118.       _loc1_.cTime = _loc1_.startTime;
  119.       _loc1_.oCitizens.reset();
  120.       _loc1_.oCitizens.setLevel(_loc1_.level);
  121.       _loc1_.oGerms.reset();
  122.       _loc1_.moveView = _loc1_.moveViewGame;
  123.       _loc1_.endCheck = _loc1_.endCheckGame;
  124.       _loc1_.cTime = _loc1_.startTime;
  125.       _loc1_.cTimeRatio = 0;
  126.       _loc1_.nTime = Math.max(_loc1_.nFullTime - _loc1_.nTimeDec * _loc1_.level,_loc1_.nLowerTimeLimit);
  127.       _loc1_.nDistRatio = 0;
  128.       _loc1_.oBundle.reset();
  129.       if(_loc2_.bHelp == false)
  130.       {
  131.          _loc2_.mcRoot.startPopup.go();
  132.       }
  133.       if(_loc2_.bMute == false)
  134.       {
  135.          if(_loc2_.bHelp == false)
  136.          {
  137.             _loc2_.mcRoot.mcMusic.play();
  138.          }
  139.       }
  140.    }
  141.    function endLevelPrep()
  142.    {
  143.       var _loc1_ = this;
  144.       _loc1_.endCheck = _loc1_.endCheckEnd;
  145.       _loc1_.oBuildings.addHome();
  146.    }
  147.    function endLevel()
  148.    {
  149.       var _loc1_ = this;
  150.       var _loc3_ = _global;
  151.       _quality = "HIGH";
  152.       _loc3_.mcRoot.mcMusic.oSound.stop();
  153.       if(smashing.Viewport.x < _loc1_.nDist)
  154.       {
  155.          _loc1_.lives = _loc1_.lives - 1;
  156.          if(_loc1_.lives <= 0)
  157.          {
  158.             _loc1_.endGame();
  159.          }
  160.          else
  161.          {
  162.             _loc3_.mcRoot.mcMenu.show("noTime");
  163.          }
  164.       }
  165.       else if(_loc1_.oPlayer.germs < _loc1_.germReq)
  166.       {
  167.          _loc1_.lives = _loc1_.lives - 1;
  168.          if(_loc1_.lives <= 0)
  169.          {
  170.             _loc1_.endGame();
  171.          }
  172.          else
  173.          {
  174.             _loc3_.mcRoot.mcMenu.show("noGerms");
  175.          }
  176.       }
  177.       else
  178.       {
  179.          var finalRatio = _loc1_.nDistRatio - _loc1_.cTimeRatio;
  180.          var _loc2_ = Math.floor(finalRatio * _loc1_.timeBonus);
  181.          smashing.Menu.target.timeBonus = _loc2_;
  182.          smashing.Menu.target.oldScore = _loc1_.score;
  183.          _loc1_.score += _loc2_;
  184.          smashing.Menu.target.newScore = _loc1_.score;
  185.          _loc3_.mcRoot.mcMenu.show("levelEnd");
  186.          _loc1_.level = _loc1_.level + 1;
  187.       }
  188.    }
  189.    function endGame()
  190.    {
  191.       var _loc1_ = _global;
  192.       _quality = "HIGH";
  193.       _loc1_.mcRoot.oBase.pause();
  194.       _loc1_.mcRoot.finalScore = this.score;
  195.       _loc1_.mcRoot.gotoAndStop("end");
  196.    }
  197.    function reset()
  198.    {
  199.       this.cTime = this.startTime;
  200.    }
  201.    function moveViewGame(nElapsed)
  202.    {
  203.       var _loc1_ = this;
  204.       smashing.Viewport.y = _loc1_.oPlayer.y;
  205.       var lowBound = BuildingHandler.floor - smashing.Viewport.halfHeight + 15;
  206.       if(smashing.Viewport.y > lowBound)
  207.       {
  208.          smashing.Viewport.y = lowBound;
  209.       }
  210.       else
  211.       {
  212.          var highBound = BuildingHandler.ceiling + smashing.Viewport.halfHeight;
  213.          if(smashing.Viewport.y < highBound)
  214.          {
  215.             smashing.Viewport.y = highBound;
  216.          }
  217.       }
  218.       var _loc3_ = _loc1_.oPlayer.x + _loc1_.playerOffset;
  219.       if(_loc3_ > smashing.Viewport.startX)
  220.       {
  221.          smashing.Viewport.x = _loc3_;
  222.       }
  223.       else
  224.       {
  225.          smashing.Viewport.x = smashing.Viewport.startX;
  226.       }
  227.       var _loc2_ = BuildingHandler.homeLimit;
  228.       if(_loc2_ != undefined)
  229.       {
  230.          if(smashing.Viewport.x > _loc2_)
  231.          {
  232.             smashing.Viewport.x = _loc2_;
  233.          }
  234.       }
  235.       if(smashing.Viewport.x > _loc1_.howFar)
  236.       {
  237.          _loc1_.howFar = smashing.Viewport.x;
  238.       }
  239.    }
  240.    function moveViewEnd(nElapsed)
  241.    {
  242.       smashing.Viewport.y = this.oPlayer.y;
  243.       var _loc2_ = BuildingHandler.floor - smashing.Viewport.halfHeight + 15;
  244.       if(smashing.Viewport.y > _loc2_)
  245.       {
  246.          smashing.Viewport.y = _loc2_;
  247.       }
  248.       else
  249.       {
  250.          var highBound = BuildingHandler.ceiling + smashing.Viewport.halfHeight;
  251.          if(smashing.Viewport.y < highBound)
  252.          {
  253.             smashing.Viewport.y = highBound;
  254.          }
  255.       }
  256.       var _loc1_ = this.oPlayer.x + this.playerOffset;
  257.       if(_loc1_ - smashing.Viewport.x > 0)
  258.       {
  259.          smashing.Viewport.x = _loc1_;
  260.       }
  261.       var _loc3_ = BuildingHandler.home;
  262.       var rightBorder = _loc3_.x + _loc3_._width - smashing.Viewport.halfWidth;
  263.       if(smashing.Viewport.x > rightBorder)
  264.       {
  265.          smashing.Viewport.x = rightBorder;
  266.       }
  267.    }
  268.    function endCheckGame()
  269.    {
  270.       var _loc1_ = this;
  271.       if(_loc1_.cTimeRatio > _loc1_.nDistRatio)
  272.       {
  273.          _loc1_.endLevel();
  274.       }
  275.       if(smashing.Viewport.x >= _loc1_.nDist)
  276.       {
  277.          _loc1_.endLevelPrep();
  278.       }
  279.    }
  280.    function endCheckEnd()
  281.    {
  282.       var _loc1_ = this;
  283.       if(_loc1_.cTimeRatio > _loc1_.nDistRatio)
  284.       {
  285.          _loc1_.endLevel();
  286.       }
  287.       if(_loc1_.oPlayer.hitTest(BuildingHandler.home.mcHitArea))
  288.       {
  289.          _loc1_.endLevel();
  290.       }
  291.    }
  292.    static function addScore(nScore)
  293.    {
  294.       MaggieWorld.target.score += nScore;
  295.    }
  296. }
  297.