home *** CD-ROM | disk | FTP | other *** search
- class Citizen extends smashing.Renderable
- {
- var m;
- var oBuildings;
- var x;
- var y;
- var gfx;
- var update;
- var oCitizenHandler;
- var r = 27;
- var speed = 150;
- var cMove = 0;
- var nSine = 120;
- static var nRange = 20;
- var sType = "citizen";
- var bounce = 500;
- var bDead = false;
- var nDie = 2;
- var cDie = 0;
- function Citizen()
- {
- var _loc1_ = this;
- super();
- _loc1_.gotoAndStop(Math.ceil(Math.random() * _loc1_._totalframes));
- _loc1_.update = _loc1_.updateNormal;
- }
- function updateNormal(nElapsed)
- {
- var _loc1_ = this;
- var _loc2_ = nElapsed * _loc1_.speed;
- _loc1_.x -= _loc2_;
- _loc1_.cMove += _loc2_;
- _loc1_.y = _loc1_.baseY + Citizen.nRange * Math.sin(3.141592653589793 * _loc1_.cMove / _loc1_.nSine);
- var _loc3_ = _loc1_.x - smashing.Viewport.x;
- if(_loc3_ <= - (smashing.Viewport.halfWidth + _loc1_.r))
- {
- _loc1_.oCitizenHandler.removeCitizen(_loc1_);
- }
- }
- function updateDizzy(nElapsed)
- {
- var g = smashing.Phys.gr * nElapsed;
- this.m.y += g;
- var mot = this.m.multiply(nElapsed);
- var clips = this.oBuildings.oHandler.clips;
- var l = clips.length;
- var l2;
- var aLines;
- var _loc1_ = undefined;
- var _loc3_ = null;
- var mcC;
- var p = new smashing.Point(this.x,this.y);
- var i = 0;
- while(i < l)
- {
- mcC = clips[i];
- if(mcC.hasObstacle == true)
- {
- if(mcC.hitTest(this) == true)
- {
- aLines = mcC.aLines;
- l2 = aLines.length;
- var _loc2_ = 0;
- while(_loc2_ < l2)
- {
- if(!smashing.Misc.isHoriz(aLines[_loc2_]))
- {
- _loc1_ = aLines[_loc2_].collisionPoint(p,this.m,this.r);
- }
- if(_loc3_ == null && _loc1_ != null)
- {
- _loc3_ = _loc1_;
- }
- else if(_loc1_.distSqu < _loc3_.distSqu && _loc1_ != null)
- {
- _loc3_ = _loc1_;
- }
- _loc2_ = _loc2_ + 1;
- }
- }
- }
- i++;
- }
- if(_loc3_ != null)
- {
- var pHit = new smashing.Point(_loc3_.hit.x,_loc3_.hit.y);
- this.x = pHit.x;
- this.y = pHit.y;
- this.gfx.gotoAndStop("DIE!");
- this.update = this.updateLand;
- }
- else
- {
- this.x += mot.x;
- this.y += mot.y;
- if(this.y + this.r - smashing.Viewport.y > smashing.Viewport.halfWidth)
- {
- this.oCitizenHandler.removeCitizen(this);
- }
- }
- var myFloor = BuildingHandler.floor - 80;
- if(this.y + this.r > myFloor)
- {
- this.y = myFloor;
- this.gfx.gotoAndStop("DIE!");
- this.update = this.updateLand;
- }
- }
- function updateLand(nElapsed)
- {
- var _loc1_ = this;
- _loc1_.cDie += nElapsed;
- if(_loc1_.cDie >= _loc1_.nDie)
- {
- _loc1_.oCitizenHandler.removeCitizen(_loc1_);
- }
- if(_loc1_.y + _loc1_.r - smashing.Viewport.y > smashing.Viewport.halfWidth)
- {
- _loc1_.oCitizenHandler.removeCitizen(_loc1_);
- }
- }
- function render()
- {
- var _loc2_ = this;
- var _loc1_ = smashing.Viewport.getPos(_loc2_);
- _loc2_._x = _loc1_.x + smashing.Viewport.centerX;
- _loc2_._y = _loc1_.y + smashing.Viewport.centerY;
- }
- function collisionTest(oPlayer)
- {
- var _loc2_ = oPlayer;
- var _loc1_ = new smashing.Point(_loc2_.x - this.x,_loc2_.y - this.y);
- var _loc3_ = _loc1_.y;
- _loc1_.y += _loc2_.r * _loc2_.nCrouchMod * (_loc3_ / Math.abs(_loc3_));
- var r2 = Math.pow(this.r + _loc2_.r,2);
- if(_loc1_.dot(_loc1_) < r2)
- {
- return true;
- }
- return false;
- }
- function react(oPlayer, nElapsed)
- {
- var _loc1_ = this;
- oPlayer.hurt();
- _loc1_.m = new smashing.Point(1,-1);
- _loc1_.m.length = _loc1_.bounce;
- _loc1_.gfx.gotoAndStop("hit");
- _loc1_.update = _loc1_.updateDizzy;
- _loc1_.bDead = true;
- }
- }
-