home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / starisland.swf / scripts / __Packages / org / cove / flade / surfaces / RectangleTile.as < prev    next >
Encoding:
Text File  |  2007-12-10  |  3.1 KB  |  115 lines

  1. class org.cove.flade.surfaces.RectangleTile extends org.cove.flade.surfaces.AbstractTile implements org.cove.flade.surfaces.Surface
  2. {
  3.    var rectWidth;
  4.    var rectHeight;
  5.    var isVisible;
  6.    var dmc;
  7.    var center;
  8.    var normal;
  9.    var minX;
  10.    var maxX;
  11.    var minY;
  12.    var maxY;
  13.    function RectangleTile(cx, cy, rw, rh, rootmc)
  14.    {
  15.       super(cx,cy,rootmc);
  16.       this.rectWidth = rw;
  17.       this.rectHeight = rh;
  18.       this.createBoundingRect(rw,rh);
  19.    }
  20.    function paint()
  21.    {
  22.       if(this.isVisible)
  23.       {
  24.          this.dmc.clear();
  25.          this.dmc.lineStyle(0,2237064,100);
  26.          org.cove.flade.graphics.Graphics.paintRectangle(this.dmc,this.center.x,this.center.y,this.rectWidth,this.rectHeight);
  27.       }
  28.    }
  29.    function resolveCircleCollision(p, sysObj)
  30.    {
  31.       if(this.isCircleColliding(p))
  32.       {
  33.          this.onContact();
  34.          p.resolveCollision(this.normal,sysObj);
  35.          p.SetCollision();
  36.       }
  37.    }
  38.    function resolveRectangleCollision(p, sysObj)
  39.    {
  40.       if(this.isRectangleColliding(p))
  41.       {
  42.          this.onContact();
  43.          p.resolveCollision(this.normal,sysObj);
  44.          p.SetCollision();
  45.       }
  46.    }
  47.    function isCircleColliding(p)
  48.    {
  49.       p.getCardXProjection();
  50.       var _loc6_ = this.testIntervals(p.bmin,p.bmax,this.minX,this.maxX);
  51.       if(_loc6_ == 0)
  52.       {
  53.          return false;
  54.       }
  55.       p.getCardYProjection();
  56.       var _loc5_ = this.testIntervals(p.bmin,p.bmax,this.minY,this.maxY);
  57.       if(_loc5_ == 0)
  58.       {
  59.          return false;
  60.       }
  61.       var _loc11_ = Math.abs(_loc6_) < p.radius;
  62.       var _loc12_ = Math.abs(_loc5_) < p.radius;
  63.       if(_loc11_ && _loc12_)
  64.       {
  65.          var _loc10_ = this.center.x + this.sign(p.curr.x - this.center.x) * (this.rectWidth / 2);
  66.          var _loc9_ = this.center.y + this.sign(p.curr.y - this.center.y) * (this.rectHeight / 2);
  67.          var _loc4_ = p.curr.x - _loc10_;
  68.          var _loc3_ = p.curr.y - _loc9_;
  69.          var _loc8_ = Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  70.          var _loc7_ = p.radius - _loc8_;
  71.          if(_loc7_ > 0)
  72.          {
  73.             _loc4_ /= _loc8_;
  74.             _loc3_ /= _loc8_;
  75.             p.mtd.setTo(_loc4_ * _loc7_,_loc3_ * _loc7_);
  76.             this.normal.setTo(_loc4_,_loc3_);
  77.             return true;
  78.          }
  79.          return false;
  80.       }
  81.       p.setXYMTD(_loc6_,_loc5_);
  82.       this.normal.setTo(p.mtd.x / Math.abs(_loc6_),p.mtd.y / Math.abs(_loc5_));
  83.       return true;
  84.    }
  85.    function isRectangleColliding(p)
  86.    {
  87.       p.getCardXProjection();
  88.       var _loc4_ = this.testIntervals(p.bmin,p.bmax,this.minX,this.maxX);
  89.       if(_loc4_ == 0)
  90.       {
  91.          return false;
  92.       }
  93.       p.getCardYProjection();
  94.       var _loc3_ = this.testIntervals(p.bmin,p.bmax,this.minY,this.maxY);
  95.       if(_loc3_ == 0)
  96.       {
  97.          return false;
  98.       }
  99.       p.setXYMTD(_loc4_,_loc3_);
  100.       this.normal.setTo(p.mtd.x / Math.abs(_loc4_),p.mtd.y / Math.abs(_loc3_));
  101.       return true;
  102.    }
  103.    function sign(val)
  104.    {
  105.       if(val < 0)
  106.       {
  107.          return -1;
  108.       }
  109.       if(val > 0)
  110.       {
  111.          return 1;
  112.       }
  113.    }
  114. }
  115.