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

  1. class Citizen extends smashing.Renderable
  2. {
  3.    var m;
  4.    var oBuildings;
  5.    var x;
  6.    var y;
  7.    var gfx;
  8.    var update;
  9.    var oCitizenHandler;
  10.    var r = 27;
  11.    var speed = 150;
  12.    var cMove = 0;
  13.    var nSine = 120;
  14.    static var nRange = 20;
  15.    var sType = "citizen";
  16.    var bounce = 500;
  17.    var bDead = false;
  18.    var nDie = 2;
  19.    var cDie = 0;
  20.    function Citizen()
  21.    {
  22.       var _loc1_ = this;
  23.       super();
  24.       _loc1_.gotoAndStop(Math.ceil(Math.random() * _loc1_._totalframes));
  25.       _loc1_.update = _loc1_.updateNormal;
  26.    }
  27.    function updateNormal(nElapsed)
  28.    {
  29.       var _loc1_ = this;
  30.       var _loc2_ = nElapsed * _loc1_.speed;
  31.       _loc1_.x -= _loc2_;
  32.       _loc1_.cMove += _loc2_;
  33.       _loc1_.y = _loc1_.baseY + Citizen.nRange * Math.sin(3.141592653589793 * _loc1_.cMove / _loc1_.nSine);
  34.       var _loc3_ = _loc1_.x - smashing.Viewport.x;
  35.       if(_loc3_ <= - (smashing.Viewport.halfWidth + _loc1_.r))
  36.       {
  37.          _loc1_.oCitizenHandler.removeCitizen(_loc1_);
  38.       }
  39.    }
  40.    function updateDizzy(nElapsed)
  41.    {
  42.       var g = smashing.Phys.gr * nElapsed;
  43.       this.m.y += g;
  44.       var mot = this.m.multiply(nElapsed);
  45.       var clips = this.oBuildings.oHandler.clips;
  46.       var l = clips.length;
  47.       var l2;
  48.       var aLines;
  49.       var _loc1_ = undefined;
  50.       var _loc3_ = null;
  51.       var mcC;
  52.       var p = new smashing.Point(this.x,this.y);
  53.       var i = 0;
  54.       while(i < l)
  55.       {
  56.          mcC = clips[i];
  57.          if(mcC.hasObstacle == true)
  58.          {
  59.             if(mcC.hitTest(this) == true)
  60.             {
  61.                aLines = mcC.aLines;
  62.                l2 = aLines.length;
  63.                var _loc2_ = 0;
  64.                while(_loc2_ < l2)
  65.                {
  66.                   if(!smashing.Misc.isHoriz(aLines[_loc2_]))
  67.                   {
  68.                      _loc1_ = aLines[_loc2_].collisionPoint(p,this.m,this.r);
  69.                   }
  70.                   if(_loc3_ == null && _loc1_ != null)
  71.                   {
  72.                      _loc3_ = _loc1_;
  73.                   }
  74.                   else if(_loc1_.distSqu < _loc3_.distSqu && _loc1_ != null)
  75.                   {
  76.                      _loc3_ = _loc1_;
  77.                   }
  78.                   _loc2_ = _loc2_ + 1;
  79.                }
  80.             }
  81.          }
  82.          i++;
  83.       }
  84.       if(_loc3_ != null)
  85.       {
  86.          var pHit = new smashing.Point(_loc3_.hit.x,_loc3_.hit.y);
  87.          this.x = pHit.x;
  88.          this.y = pHit.y;
  89.          this.gfx.gotoAndStop("DIE!");
  90.          this.update = this.updateLand;
  91.       }
  92.       else
  93.       {
  94.          this.x += mot.x;
  95.          this.y += mot.y;
  96.          if(this.y + this.r - smashing.Viewport.y > smashing.Viewport.halfWidth)
  97.          {
  98.             this.oCitizenHandler.removeCitizen(this);
  99.          }
  100.       }
  101.       var myFloor = BuildingHandler.floor - 80;
  102.       if(this.y + this.r > myFloor)
  103.       {
  104.          this.y = myFloor;
  105.          this.gfx.gotoAndStop("DIE!");
  106.          this.update = this.updateLand;
  107.       }
  108.    }
  109.    function updateLand(nElapsed)
  110.    {
  111.       var _loc1_ = this;
  112.       _loc1_.cDie += nElapsed;
  113.       if(_loc1_.cDie >= _loc1_.nDie)
  114.       {
  115.          _loc1_.oCitizenHandler.removeCitizen(_loc1_);
  116.       }
  117.       if(_loc1_.y + _loc1_.r - smashing.Viewport.y > smashing.Viewport.halfWidth)
  118.       {
  119.          _loc1_.oCitizenHandler.removeCitizen(_loc1_);
  120.       }
  121.    }
  122.    function render()
  123.    {
  124.       var _loc2_ = this;
  125.       var _loc1_ = smashing.Viewport.getPos(_loc2_);
  126.       _loc2_._x = _loc1_.x + smashing.Viewport.centerX;
  127.       _loc2_._y = _loc1_.y + smashing.Viewport.centerY;
  128.    }
  129.    function collisionTest(oPlayer)
  130.    {
  131.       var _loc2_ = oPlayer;
  132.       var _loc1_ = new smashing.Point(_loc2_.x - this.x,_loc2_.y - this.y);
  133.       var _loc3_ = _loc1_.y;
  134.       _loc1_.y += _loc2_.r * _loc2_.nCrouchMod * (_loc3_ / Math.abs(_loc3_));
  135.       var r2 = Math.pow(this.r + _loc2_.r,2);
  136.       if(_loc1_.dot(_loc1_) < r2)
  137.       {
  138.          return true;
  139.       }
  140.       return false;
  141.    }
  142.    function react(oPlayer, nElapsed)
  143.    {
  144.       var _loc1_ = this;
  145.       oPlayer.hurt();
  146.       _loc1_.m = new smashing.Point(1,-1);
  147.       _loc1_.m.length = _loc1_.bounce;
  148.       _loc1_.gfx.gotoAndStop("hit");
  149.       _loc1_.update = _loc1_.updateDizzy;
  150.       _loc1_.bDead = true;
  151.    }
  152. }
  153.