home *** CD-ROM | disk | FTP | other *** search
- class BuildingHandler
- {
- var oHandler;
- var tileBottomPlacement;
- var oGerms;
- var tileMidPlacement;
- var tileTopPlacement;
- var aBuild;
- static var tileWidth;
- static var home;
- static var tileWidthBot;
- static var leftEdge;
- static var topEdge;
- static var tileHeightBot;
- static var tileHeightMid;
- static var tileHeightTop;
- static var floor;
- static var ceiling;
- static var homeLimit;
- static var tileWidthMid;
- static var tileWidthTop;
- var bAdd = false;
- var nGermChance = 5;
- var powerChance = 10;
- var nTypes = 7;
- var nTotalGerms = 0;
- function BuildingHandler(loc)
- {
- var _loc1_ = this;
- _loc1_.location = loc;
- _loc1_.oHandler = new smashing.ClipHandler(_loc1_.location);
- _loc1_.aPower = ["BonusInvun","BonusTime","BonusSpeed"];
- }
- function update(nElapsed)
- {
- var _loc2_ = this.oHandler.clips;
- var _loc3_ = _loc2_.length;
- var _loc1_ = 0;
- while(_loc1_ < _loc3_)
- {
- _loc2_[_loc1_].render();
- _loc1_ = _loc1_ + 1;
- }
- if(this.bAdd == true)
- {
- this.addBuilding();
- }
- }
- function render()
- {
- var _loc3_ = this;
- var pos = smashing.Viewport.x + smashing.Viewport.halfWidth;
- var backPos = pos - smashing.Viewport.width;
- var index = Math.floor(pos / BuildingHandler.tileWidth) + 1;
- var backIndex = Math.floor(backPos / BuildingHandler.tileWidth);
- if(index > _loc3_.aBuild.length)
- {
- _loc3_.addBuilding(_loc3_.oWorld.level);
- }
- var _loc2_ = undefined;
- var _loc1_ = backIndex;
- while(_loc1_ < index)
- {
- _loc2_ = _loc3_.aBuild[_loc1_];
- if(_loc2_.bOnStage == false)
- {
- _loc3_.buildOnStage(_loc2_);
- }
- _loc1_ = _loc1_ + 1;
- }
- var clips = _loc3_.oHandler.clips;
- var l = clips.length;
- _loc1_ = 0;
- while(_loc1_ < l)
- {
- clips[_loc1_].render();
- _loc1_ = _loc1_ + 1;
- }
- }
- function reset()
- {
- var _loc1_ = this;
- _loc1_.oHandler.removeAllClips();
- BuildingHandler.home = null;
- _loc1_.aBuild = [];
- _loc1_.init();
- }
- function init()
- {
- var _loc1_ = this;
- BuildingHandler.tileWidth = BuildingHandler.tileWidthBot;
- BuildingHandler.leftEdge = - (smashing.Viewport.halfWidth + BuildingHandler.tileWidth);
- BuildingHandler.topEdge = - smashing.Viewport.halfHeight;
- _loc1_.tileBottomPlacement = smashing.Viewport.height - BuildingHandler.tileHeightBot;
- _loc1_.tileMidPlacement = _loc1_.tileBottomPlacement - BuildingHandler.tileHeightMid;
- _loc1_.tileTopPlacement = _loc1_.tileMidPlacement - BuildingHandler.tileHeightTop;
- BuildingHandler.floor = _loc1_.tileBottomPlacement + BuildingHandler.tileHeightBot - 15;
- BuildingHandler.ceiling = smashing.Viewport.height - BuildingHandler.tileHeightBot - BuildingHandler.tileHeightMid - BuildingHandler.tileHeightTop;
- _loc1_.addBuilding(_loc1_.oWorld.level,false);
- _loc1_.addBuilding(_loc1_.oWorld.level,false);
- _loc1_.addBuilding(_loc1_.oWorld.level);
- _loc1_.addBuilding(_loc1_.oWorld.level);
- _loc1_.render();
- _loc1_.nArrayLimit = Math.ceil(_loc1_.oWorld.nDist / BuildingHandler.tileWidth);
- }
- function removeBuilding(o, remove)
- {
- var _loc1_ = o;
- if(_loc1_.mcGerm != null)
- {
- _loc1_.mcGerm.handler.removeClip(_loc1_.mcGerm);
- }
- _loc1_.oData.bOnStage = false;
- this.oHandler.removeClip(_loc1_);
- }
- function addBuilding(nLevel, bObst)
- {
- var _loc2_ = this;
- var _loc3_ = bObst;
- if(BuildingHandler.home == null)
- {
- var _loc1_ = new BData();
- _loc1_.nType = Math.ceil(Math.random() * _loc2_.nTypes);
- _loc1_.nLevel = (nLevel - 1) % 3;
- if(_loc3_ == undefined)
- {
- _loc3_ = smashing.Misc.rndBool();
- if(_loc3_ == false)
- {
- _loc1_.bObstBot = false;
- _loc1_.sPowerupBot = _loc2_.shouldAddPowerup();
- }
- else
- {
- _loc1_.bObstBot = true;
- _loc2_.nTotalGerms += Number(_loc1_.bGermBot = _loc2_.shouldAddGerm());
- }
- }
- else
- {
- _loc1_.sPowerupBot = null;
- _loc1_.bObstBot = false;
- }
- if(smashing.Misc.rndBool())
- {
- _loc1_.bObstMid = true;
- _loc2_.nTotalGerms += Number(_loc1_.bGermMid = _loc2_.shouldAddGerm());
- }
- else
- {
- _loc1_.bObstMid = false;
- _loc1_.sPowerupMid = _loc2_.shouldAddPowerup();
- }
- if(smashing.Misc.rndBool())
- {
- _loc1_.bObstTop = true;
- _loc2_.nTotalGerms += Number(_loc1_.bGermTop = _loc2_.shouldAddGerm());
- }
- else
- {
- _loc1_.bObstTop = false;
- _loc1_.sPowerupTop = _loc2_.shouldAddPowerup();
- }
- _loc1_.x = _loc2_.aBuild.length * BuildingHandler.tileWidth;
- if(_loc2_.nArrayLimit - _loc2_.aBuild.length < 10 - _loc2_.nTotalGerms)
- {
- switch(Math.floor(Math.random() * 3))
- {
- case 0:
- _loc1_.bGermBot = true;
- break;
- case 1:
- _loc1_.bGermMid = true;
- break;
- case 2:
- _loc1_.bGermTop = true;
- }
- }
- _loc2_.aBuild.push(_loc1_);
- }
- }
- function buildOnStage(oBuild)
- {
- var _loc1_ = oBuild;
- _loc1_.bOnStage = true;
- if(_loc1_.bHome == false)
- {
- var _loc3_ = undefined;
- var _loc2_ = undefined;
- var build = this.oHandler.addClip("mcBuildingBottom" + _loc1_.nLevel);
- build.x = _loc1_.x;
- build.y = this.tileBottomPlacement;
- build.init(this,_loc1_.bObstBot,_loc1_.nType,_loc1_,0);
- if(_loc1_.sPowerupBot != null)
- {
- _loc3_ = this.oGerms.addGerm(build.x + build.mcBonusLoc._x,build.y + build.mcBonusLoc._y,_loc1_.sPowerupBot);
- _loc3_.oData = _loc1_;
- _loc3_.nSegment = 0;
- _loc3_.mcBuild = build;
- build.mcGerm = _loc3_;
- }
- else if(_loc1_.bGermBot == true)
- {
- _loc2_ = this.oGerms.addGerm(build.x + build.gfx.mcGermPlacer._x,build.y + build.gfx.mcGermPlacer._y,"mcGerm");
- _loc2_.oData = _loc1_;
- _loc2_.nSegment = 0;
- _loc2_.mcBuild = build;
- build.mcGerm = _loc2_;
- }
- build = this.oHandler.addClip("mcBuildingMiddle" + _loc1_.nLevel);
- build.x = _loc1_.x;
- build.y = this.tileMidPlacement;
- build.init(this,_loc1_.bObstMid,_loc1_.nType,_loc1_,0);
- if(_loc1_.sPowerupMid != null)
- {
- _loc3_ = this.oGerms.addGerm(build.x + build.mcBonusLoc._x,build.y + build.mcBonusLoc._y,_loc1_.sPowerupMid);
- _loc3_.oData = _loc1_;
- _loc3_.nSegment = 1;
- _loc3_.mcBuild = build;
- build.mcGerm = _loc3_;
- }
- else if(_loc1_.bGermMid == true)
- {
- _loc2_ = this.oGerms.addGerm(build.x + build.gfx.mcGermPlacer._x,build.y + build.gfx.mcGermPlacer._y,"mcGerm");
- _loc2_.oData = _loc1_;
- _loc2_.nSegment = 1;
- _loc2_.mcBuild = build;
- build.mcGerm = _loc2_;
- }
- build = this.oHandler.addClip("mcBuildingTop" + _loc1_.nLevel);
- build.x = _loc1_.x;
- build.y = this.tileTopPlacement;
- build.init(this,_loc1_.bObstTop,_loc1_.nType,_loc1_,0);
- if(_loc1_.sPowerupTop != null)
- {
- _loc3_ = this.oGerms.addGerm(build.x + build.mcBonusLoc._x,build.y + build.mcBonusLoc._y,_loc1_.sPowerupTop);
- _loc3_.oData = _loc1_;
- _loc3_.nSegment = 2;
- _loc3_.mcBuild = build;
- build.mcGerm = _loc3_;
- }
- else if(_loc1_.bGermTop == true)
- {
- _loc2_ = this.oGerms.addGerm(build.x + build.gfx.mcGermPlacer._x,build.y + build.gfx.mcGermPlacer._y,"mcGerm");
- _loc2_.oData = _loc1_;
- _loc2_.nSegment = 2;
- _loc2_.mcBuild = build;
- build.mcGerm = _loc2_;
- }
- }
- else
- {
- var build = this.oHandler.addClip("home");
- build.x = _loc1_.x;
- build.y = BuildingHandler.floor - build._height - 50;
- BuildingHandler.homeLimit = build.x + BuildingHandler.tileWidth - smashing.Viewport.halfWidth;
- BuildingHandler.home = build;
- }
- }
- function addHome()
- {
- var _loc1_ = new BData();
- _loc1_.bHome = true;
- _loc1_.x = this.aBuild.length * BuildingHandler.tileWidth;
- this.aBuild.push(_loc1_);
- }
- function shouldAddGerm()
- {
- return 0 == Math.floor(Math.random() * this.nGermChance);
- }
- function shouldAddPowerup()
- {
- var _loc1_ = this;
- if(0 == Math.floor(Math.random() * _loc1_.powerChance))
- {
- return _loc1_.aPower[Math.floor(Math.random() * _loc1_.aPower.length)];
- }
- return null;
- }
- }
-