home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / starisland.swf / scripts / __Packages / illusoft / utils / RoundedRectangle.as < prev    next >
Encoding:
Text File  |  2007-12-10  |  5.0 KB  |  148 lines

  1. class illusoft.utils.RoundedRectangle extends org.cove.flade.surfaces.AbstractTile implements org.cove.flade.surfaces.Surface
  2. {
  3.    var rectWidth;
  4.    var rectHeight;
  5.    var radius;
  6.    var lineLeft;
  7.    var lineRight;
  8.    var lineTop;
  9.    var lineBottom;
  10.    var circleTopLeft;
  11.    var circleTopRight;
  12.    var circleBottomLeft;
  13.    var circleBottomRight;
  14.    var isVisible;
  15.    var normal;
  16.    var minX;
  17.    var maxX;
  18.    var minY;
  19.    var maxY;
  20.    var center;
  21.    function RoundedRectangle(cx, cy, rw, rh, radius, engine, char, rootMC)
  22.    {
  23.       super(cx,cy,rootMC);
  24.       this.rectWidth = rw;
  25.       this.rectHeight = rh;
  26.       this.radius = radius;
  27.       var _loc8_ = cx - rw / 2;
  28.       var _loc6_ = cx + rw / 2;
  29.       var _loc7_ = cy - rh / 2;
  30.       var _loc5_ = cy + rh / 2;
  31.       var char = char;
  32.       this.lineLeft = new org.cove.flade.surfaces.LineSurface(_loc8_,_loc5_ - radius,_loc8_,_loc7_ + radius,rootMC);
  33.       this.lineRight = new org.cove.flade.surfaces.LineSurface(_loc6_,_loc7_ + radius,_loc6_,_loc5_ - radius,rootMC);
  34.       this.lineTop = new org.cove.flade.surfaces.LineSurface(_loc8_ + radius,_loc7_,_loc6_ - radius,_loc7_,rootMC);
  35.       this.lineBottom = new org.cove.flade.surfaces.LineSurface(_loc6_ - radius,_loc5_,_loc8_ + radius,_loc5_,rootMC);
  36.       this.lineTop.onContact = function()
  37.       {
  38.          char.AllowJump(true);
  39.       };
  40.       this.circleTopLeft = new org.cove.flade.surfaces.CircleTile(_loc8_ + radius,_loc7_ + radius,radius,rootMC);
  41.       this.circleTopLeft.onContact = this.lineTop.onContact;
  42.       this.circleTopRight = new org.cove.flade.surfaces.CircleTile(_loc6_ - radius,_loc7_ + radius,radius,rootMC);
  43.       this.circleTopRight.onContact = this.lineTop.onContact;
  44.       this.circleBottomLeft = new org.cove.flade.surfaces.CircleTile(_loc8_ + radius,_loc5_ - radius,radius,rootMC);
  45.       this.circleBottomRight = new org.cove.flade.surfaces.CircleTile(_loc6_ - radius,_loc5_ - radius,radius,rootMC);
  46.    }
  47.    function paint()
  48.    {
  49.       if(this.isVisible)
  50.       {
  51.          this.lineLeft.paint();
  52.          this.lineRight.paint();
  53.          this.lineTop.paint();
  54.          this.lineBottom.paint();
  55.          this.circleTopLeft.paint();
  56.          this.circleTopRight.paint();
  57.          this.circleBottomLeft.paint();
  58.          this.circleBottomRight.paint();
  59.       }
  60.    }
  61.    function resolveCircleCollision(p, sysObj)
  62.    {
  63.       this.lineLeft.resolveCircleCollision(p,sysObj);
  64.       this.lineRight.resolveCircleCollision(p,sysObj);
  65.       this.lineBottom.resolveCircleCollision(p,sysObj);
  66.       this.lineTop.resolveCircleCollision(p,sysObj);
  67.       this.circleTopLeft.resolveCircleCollision(p,sysObj);
  68.       this.circleTopRight.resolveCircleCollision(p,sysObj);
  69.       this.circleBottomLeft.resolveCircleCollision(p,sysObj);
  70.       this.circleBottomRight.resolveCircleCollision(p,sysObj);
  71.    }
  72.    function resolveRectangleCollision(p, sysObj)
  73.    {
  74.       if(this.isRectangleColliding(p))
  75.       {
  76.          this.onContact();
  77.          p.resolveCollision(this.normal,sysObj);
  78.       }
  79.    }
  80.    function isCircleColliding(p)
  81.    {
  82.       p.getCardXProjection();
  83.       var _loc6_ = this.testIntervals(p.bmin,p.bmax,this.minX,this.maxX);
  84.       if(_loc6_ == 0)
  85.       {
  86.          return false;
  87.       }
  88.       p.getCardYProjection();
  89.       var _loc5_ = this.testIntervals(p.bmin,p.bmax,this.minY,this.maxY);
  90.       if(_loc5_ == 0)
  91.       {
  92.          return false;
  93.       }
  94.       var _loc11_ = Math.abs(_loc6_) < p.radius;
  95.       var _loc12_ = Math.abs(_loc5_) < p.radius;
  96.       if(_loc11_ && _loc12_)
  97.       {
  98.          var _loc10_ = this.center.x + this.sign(p.curr.x - this.center.x) * (this.rectWidth / 2);
  99.          var _loc9_ = this.center.y + this.sign(p.curr.y - this.center.y) * (this.rectHeight / 2);
  100.          var _loc4_ = p.curr.x - _loc10_;
  101.          var _loc3_ = p.curr.y - _loc9_;
  102.          var _loc8_ = Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
  103.          var _loc7_ = p.radius - _loc8_;
  104.          if(_loc7_ > 0)
  105.          {
  106.             _loc4_ /= _loc8_;
  107.             _loc3_ /= _loc8_;
  108.             p.mtd.setTo(_loc4_ * _loc7_,_loc3_ * _loc7_);
  109.             this.normal.setTo(_loc4_,_loc3_);
  110.             return true;
  111.          }
  112.          return false;
  113.       }
  114.       p.setXYMTD(_loc6_,_loc5_);
  115.       this.normal.setTo(p.mtd.x / Math.abs(_loc6_),p.mtd.y / Math.abs(_loc5_));
  116.       return true;
  117.    }
  118.    function isRectangleColliding(p)
  119.    {
  120.       p.getCardXProjection();
  121.       var _loc4_ = this.testIntervals(p.bmin,p.bmax,this.minX,this.maxX);
  122.       if(_loc4_ == 0)
  123.       {
  124.          return false;
  125.       }
  126.       p.getCardYProjection();
  127.       var _loc3_ = this.testIntervals(p.bmin,p.bmax,this.minY,this.maxY);
  128.       if(_loc3_ == 0)
  129.       {
  130.          return false;
  131.       }
  132.       p.setXYMTD(_loc4_,_loc3_);
  133.       this.normal.setTo(p.mtd.x / Math.abs(_loc4_),p.mtd.y / Math.abs(_loc3_));
  134.       return true;
  135.    }
  136.    function sign(val)
  137.    {
  138.       if(val < 0)
  139.       {
  140.          return -1;
  141.       }
  142.       if(val > 0)
  143.       {
  144.          return 1;
  145.       }
  146.    }
  147. }
  148.