home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / wone.swf / scripts / __Packages / CMap.as < prev    next >
Encoding:
Text File  |  2007-02-20  |  9.6 KB  |  280 lines

  1. class CMap
  2. {
  3.    var mArena;
  4.    var mBarrelCount;
  5.    var mStarCount;
  6.    var mStarIndex;
  7.    var mObjectList;
  8.    var mOverExit;
  9.    var mExitObject;
  10.    var mMap;
  11.    static var mCellSize = 110;
  12.    function CMap(tArena)
  13.    {
  14.       this.mArena = tArena;
  15.       this.mBarrelCount = this.mStarCount = this.mStarIndex = 0;
  16.       this.mObjectList = new Array();
  17.    }
  18.    function WheelCollide(tWheel, oldPosition, newPosition)
  19.    {
  20.       var _loc6_ = this.GetObjectList(tWheel,oldPosition,newPosition);
  21.       var _loc8_ = newPosition.subtract(oldPosition);
  22.       _loc8_.normalize(tWheel.mRadius);
  23.       var _loc12_ = oldPosition.clone().subtract(_loc8_);
  24.       var _loc11_ = newPosition.clone().add(_loc8_);
  25.       for(var _loc7_ in _loc6_)
  26.       {
  27.          var _loc3_ = _loc6_[_loc7_];
  28.          if(!_loc3_.mActive)
  29.          {
  30.             break;
  31.          }
  32.          switch(_loc3_.mType.toUpperCase())
  33.          {
  34.             case "LEFTSPIN":
  35.                this.mArena.mWheel.mControlLeft = true;
  36.                break;
  37.             case "RIGHTSPIN":
  38.                this.mArena.mWheel.mControlRight = true;
  39.                break;
  40.             case "BARREL":
  41.                if(this.BoxCollide(_loc3_,tWheel,newPosition) || Key.isDown(65) && _global.mCheat != undefined)
  42.                {
  43.                   _loc3_.mActive = false;
  44.                   _loc3_.play();
  45.                   if(_global.mSFXActive == true)
  46.                   {
  47.                      var _loc9_ = new Sound(_loc3_);
  48.                      _loc9_.attachSound("Barrel.Hit.wav");
  49.                      _loc9_.start(0,0);
  50.                   }
  51.                   this.mBarrelCount = this.mBarrelCount - 1;
  52.                }
  53.                break;
  54.             case "STAR":
  55.                if(this.BoxCollide(_loc3_,tWheel,newPosition) || Key.isDown(65) && _global.mCheat != undefined)
  56.                {
  57.                   _loc3_.mActive = false;
  58.                   _loc3_.play();
  59.                   if(_global.mSFXActive == true)
  60.                   {
  61.                      _loc9_ = new Sound(_loc3_);
  62.                      _loc9_.attachSound("Star.Hit.wav");
  63.                      _loc9_.start(0,0);
  64.                   }
  65.                   this.mStarCount = this.mStarCount - 1;
  66.                   this.mArena.mStats.CollectStar(_loc3_.mStarIndex,this.mStarIndex);
  67.                }
  68.                break;
  69.             case "EXIT":
  70.                if(this.mBarrelCount != 0 || this.mOverExit == true)
  71.                {
  72.                   break;
  73.                }
  74.                this.mOverExit = !(Key.isDown(65) && _global.mCheat != undefined) ? this.BoxCollide(_loc3_,tWheel,newPosition) : true;
  75.                break;
  76.          }
  77.       }
  78.       if(this.mBarrelCount == 0 && this.mExitObject.mActive == false)
  79.       {
  80.          if(_global.mSFXActive == true)
  81.          {
  82.             _loc9_ = new Sound(this.mExitObject);
  83.             _loc9_.attachSound("Exit.Open.wav");
  84.             _loc9_.setVolume(40);
  85.             _loc9_.start(0,0);
  86.          }
  87.          this.mExitObject.mActive = true;
  88.          this.mExitObject.gotoAndStop(2);
  89.       }
  90.    }
  91.    function BoxCollide(tObject, tWheel, newPosition)
  92.    {
  93.       if(newPosition.x + tWheel.mRadius >= tObject.mPList[0].x && newPosition.x - tWheel.mRadius <= tObject.mPList[2].x && newPosition.y + tWheel.mRadius >= tObject.mPList[0].y && newPosition.y - tWheel.mRadius <= tObject.mPList[2].y)
  94.       {
  95.          return true;
  96.       }
  97.       return false;
  98.    }
  99.    function LineCollide(tObject, p1, p2)
  100.    {
  101.       return CLine.LOI(tObject.mPList[0],tObject.mPList[1],p1,p2) || CLine.LOI(tObject.mPList[1],tObject.mPList[2],p1,p2) || CLine.LOI(tObject.mPList[2],tObject.mPList[3],p1,p2) || CLine.LOI(tObject.mPList[3],tObject.mPList[0],p1,p2);
  102.    }
  103.    function GetObjectList(tWheel, oldPosition, newPosition)
  104.    {
  105.       var _loc4_ = oldPosition.clone();
  106.       var _loc3_ = newPosition.clone();
  107.       if(_loc4_.x > _loc3_.x)
  108.       {
  109.          var _loc8_ = _loc4_.x;
  110.          _loc4_.x = _loc3_.x;
  111.          _loc3_.x = _loc8_;
  112.       }
  113.       if(_loc4_.y > _loc3_.y)
  114.       {
  115.          _loc8_ = _loc4_.y;
  116.          _loc4_.y = _loc3_.y;
  117.          _loc3_.y = _loc8_;
  118.       }
  119.       _loc4_ = _loc4_.subtract(tWheel.pRadius);
  120.       _loc3_ = _loc3_.add(tWheel.pRadius);
  121.       _loc4_.x = Math.floor(_loc4_.x / CMap.mCellSize);
  122.       _loc4_.y = Math.floor(_loc4_.y / CMap.mCellSize);
  123.       _loc3_.x = Math.floor(_loc3_.x / CMap.mCellSize);
  124.       _loc3_.y = Math.floor(_loc3_.y / CMap.mCellSize);
  125.       var _loc7_ = new Array();
  126.       var _loc5_ = _loc4_.y;
  127.       while(_loc5_ <= _loc3_.y)
  128.       {
  129.          var _loc6_ = this.mMap[_loc5_];
  130.          var _loc2_ = _loc4_.x;
  131.          while(_loc2_ <= _loc3_.x)
  132.          {
  133.             this.AddToLL(_loc7_,_loc6_[_loc2_]);
  134.             _loc2_ = _loc2_ + 1;
  135.          }
  136.          _loc5_ = _loc5_ + 1;
  137.       }
  138.       return _loc7_;
  139.    }
  140.    function AddToLL(ll, pll)
  141.    {
  142.       for(var _loc5_ in pll)
  143.       {
  144.          var _loc2_ = true;
  145.          for(var _loc4_ in ll)
  146.          {
  147.             if(pll[_loc5_] == ll[_loc4_])
  148.             {
  149.                _loc2_ = false;
  150.                break;
  151.             }
  152.          }
  153.          if(_loc2_ && pll[_loc5_].mActive)
  154.          {
  155.             ll[ll.length] = pll[_loc5_];
  156.          }
  157.       }
  158.    }
  159.    function AddObject(tObject, tType)
  160.    {
  161.       tObject.mActive = true;
  162.       switch(tType.toUpperCase())
  163.       {
  164.          case "LEFTSPIN":
  165.          case "RIGHTSPIN":
  166.             tObject._visible = false;
  167.             break;
  168.          case "BARREL":
  169.             this.mBarrelCount = this.mBarrelCount + 1;
  170.             break;
  171.          case "EXIT":
  172.             this.mExitObject = tObject;
  173.             this.mExitObject.mActive = false;
  174.             break;
  175.          case "STAR":
  176.             tObject.mStarIndex = this.mStarIndex;
  177.             this.mStarIndex = this.mStarIndex + 1;
  178.             if(_global.mStats.mList_AllStars[_global.mArenaIndex][tObject.mStarIndex] == true)
  179.             {
  180.                tObject._visible = false;
  181.                return undefined;
  182.             }
  183.             this.mStarCount = this.mStarCount + 1;
  184.             break;
  185.       }
  186.       tObject.mType = tType;
  187.       var _loc4_ = tObject.getBounds(tObject);
  188.       var _loc8_ = new flash.geom.Point(_loc4_.xMin,_loc4_.yMin);
  189.       var _loc7_ = new flash.geom.Point(_loc4_.xMax,_loc4_.yMin);
  190.       var _loc6_ = new flash.geom.Point(_loc4_.xMax,_loc4_.yMax);
  191.       var _loc5_ = new flash.geom.Point(_loc4_.xMin,_loc4_.yMax);
  192.       tObject.localToGlobal(_loc8_);
  193.       this.mArena.globalToLocal(_loc8_);
  194.       tObject.localToGlobal(_loc7_);
  195.       this.mArena.globalToLocal(_loc7_);
  196.       tObject.localToGlobal(_loc6_);
  197.       this.mArena.globalToLocal(_loc6_);
  198.       tObject.localToGlobal(_loc5_);
  199.       this.mArena.globalToLocal(_loc5_);
  200.       tObject.mPList = [_loc8_,_loc7_,_loc6_,_loc5_];
  201.       tObject.mPosition = new flash.geom.Point(tObject._x,tObject._y);
  202.       this.MarkMap(tObject);
  203.       tObject.cacheAsBitmap = true;
  204.       tObject.stop();
  205.       this.mObjectList[this.mObjectList.length] = tObject;
  206.    }
  207.    function MarkMap(tObject)
  208.    {
  209.       var _loc5_ = tObject.mPList[0].clone();
  210.       var _loc4_ = tObject.mPList[0].clone();
  211.       for(var _loc7_ in tObject.mPList)
  212.       {
  213.          if(tObject.mPList[_loc7_].x < _loc5_.x)
  214.          {
  215.             _loc5_.x = tObject.mPList[_loc7_].x;
  216.          }
  217.          if(tObject.mPList[_loc7_].x > _loc4_.x)
  218.          {
  219.             _loc4_.x = tObject.mPList[_loc7_].x;
  220.          }
  221.          if(tObject.mPList[_loc7_].y < _loc5_.y)
  222.          {
  223.             _loc5_.y = tObject.mPList[_loc7_].y;
  224.          }
  225.          if(tObject.mPList[_loc7_].y > _loc4_.y)
  226.          {
  227.             _loc4_.y = tObject.mPList[_loc7_].y;
  228.          }
  229.       }
  230.       _loc5_.x = Math.floor(_loc5_.x / CMap.mCellSize);
  231.       _loc5_.y = Math.floor(_loc5_.y / CMap.mCellSize);
  232.       _loc4_.x = Math.floor(_loc4_.x / CMap.mCellSize);
  233.       _loc4_.y = Math.floor(_loc4_.y / CMap.mCellSize);
  234.       var _loc6_ = _loc5_.y;
  235.       while(_loc6_ <= _loc4_.y)
  236.       {
  237.          var _loc3_ = _loc5_.x;
  238.          while(_loc3_ <= _loc4_.x)
  239.          {
  240.             this.MarkMap_Cell(tObject,new flash.geom.Point(_loc3_,_loc6_));
  241.             _loc3_ = _loc3_ + 1;
  242.          }
  243.          _loc6_ = _loc6_ + 1;
  244.       }
  245.    }
  246.    function MarkMap_Cell(tObject, p)
  247.    {
  248.       p = p.clone();
  249.       if(p.x < 0 || p.y < 0)
  250.       {
  251.          return undefined;
  252.       }
  253.       this.mMap = this.mMap != undefined ? this.mMap : (this.mMap = new Array());
  254.       this.mMap[p.y] = this.mMap[p.y] != undefined ? this.mMap[p.y] : (this.mMap[p.y] = new Array());
  255.       this.mMap[p.y][p.x] = this.mMap[p.y][p.x] != undefined ? this.mMap[p.y][p.x] : (this.mMap[p.y][p.x] = new Array());
  256.       var _loc3_ = this.mMap[p.y][p.x];
  257.       var _loc4_ = false;
  258.       for(var _loc8_ in _loc3_)
  259.       {
  260.          if(_loc3_[_loc8_] == tObject)
  261.          {
  262.             _loc4_ = true;
  263.             break;
  264.          }
  265.       }
  266.       if(!_loc4_)
  267.       {
  268.          _loc3_[_loc3_.length] = tObject;
  269.       }
  270.       var _loc7_ = p.add(new flash.geom.Point(1,1));
  271.       this.mArena.mCollisionDraw.lineStyle(0,0,100);
  272.       var _loc6_ = (this.mMap[p.y][p.x].length - 1) * 4;
  273.       this.mArena.mCollisionDraw.moveTo(p.x * CMap.mCellSize + _loc6_,p.y * CMap.mCellSize + _loc6_);
  274.       this.mArena.mCollisionDraw.lineTo(p.x * CMap.mCellSize,_loc7_.y * CMap.mCellSize);
  275.       this.mArena.mCollisionDraw.lineTo(_loc7_.x * CMap.mCellSize,_loc7_.y * CMap.mCellSize);
  276.       this.mArena.mCollisionDraw.lineTo(_loc7_.x * CMap.mCellSize,p.y * CMap.mCellSize);
  277.       this.mArena.mCollisionDraw.lineTo(p.x * CMap.mCellSize + _loc6_,p.y * CMap.mCellSize + _loc6_);
  278.    }
  279. }
  280.