home *** CD-ROM | disk | FTP | other *** search
- class illusoft.utils.RoundedRectangle extends org.cove.flade.surfaces.AbstractTile implements org.cove.flade.surfaces.Surface
- {
- var rectWidth;
- var rectHeight;
- var radius;
- var lineLeft;
- var lineRight;
- var lineTop;
- var lineBottom;
- var circleTopLeft;
- var circleTopRight;
- var circleBottomLeft;
- var circleBottomRight;
- var isVisible;
- var normal;
- var minX;
- var maxX;
- var minY;
- var maxY;
- var center;
- function RoundedRectangle(cx, cy, rw, rh, radius, engine, char, rootMC)
- {
- super(cx,cy,rootMC);
- this.rectWidth = rw;
- this.rectHeight = rh;
- this.radius = radius;
- var _loc8_ = cx - rw / 2;
- var _loc6_ = cx + rw / 2;
- var _loc7_ = cy - rh / 2;
- var _loc5_ = cy + rh / 2;
- var char = char;
- this.lineLeft = new org.cove.flade.surfaces.LineSurface(_loc8_,_loc5_ - radius,_loc8_,_loc7_ + radius,rootMC);
- this.lineRight = new org.cove.flade.surfaces.LineSurface(_loc6_,_loc7_ + radius,_loc6_,_loc5_ - radius,rootMC);
- this.lineTop = new org.cove.flade.surfaces.LineSurface(_loc8_ + radius,_loc7_,_loc6_ - radius,_loc7_,rootMC);
- this.lineBottom = new org.cove.flade.surfaces.LineSurface(_loc6_ - radius,_loc5_,_loc8_ + radius,_loc5_,rootMC);
- this.lineTop.onContact = function()
- {
- char.AllowJump(true);
- };
- this.circleTopLeft = new org.cove.flade.surfaces.CircleTile(_loc8_ + radius,_loc7_ + radius,radius,rootMC);
- this.circleTopLeft.onContact = this.lineTop.onContact;
- this.circleTopRight = new org.cove.flade.surfaces.CircleTile(_loc6_ - radius,_loc7_ + radius,radius,rootMC);
- this.circleTopRight.onContact = this.lineTop.onContact;
- this.circleBottomLeft = new org.cove.flade.surfaces.CircleTile(_loc8_ + radius,_loc5_ - radius,radius,rootMC);
- this.circleBottomRight = new org.cove.flade.surfaces.CircleTile(_loc6_ - radius,_loc5_ - radius,radius,rootMC);
- }
- function paint()
- {
- if(this.isVisible)
- {
- this.lineLeft.paint();
- this.lineRight.paint();
- this.lineTop.paint();
- this.lineBottom.paint();
- this.circleTopLeft.paint();
- this.circleTopRight.paint();
- this.circleBottomLeft.paint();
- this.circleBottomRight.paint();
- }
- }
- function resolveCircleCollision(p, sysObj)
- {
- this.lineLeft.resolveCircleCollision(p,sysObj);
- this.lineRight.resolveCircleCollision(p,sysObj);
- this.lineBottom.resolveCircleCollision(p,sysObj);
- this.lineTop.resolveCircleCollision(p,sysObj);
- this.circleTopLeft.resolveCircleCollision(p,sysObj);
- this.circleTopRight.resolveCircleCollision(p,sysObj);
- this.circleBottomLeft.resolveCircleCollision(p,sysObj);
- this.circleBottomRight.resolveCircleCollision(p,sysObj);
- }
- function resolveRectangleCollision(p, sysObj)
- {
- if(this.isRectangleColliding(p))
- {
- this.onContact();
- p.resolveCollision(this.normal,sysObj);
- }
- }
- function isCircleColliding(p)
- {
- p.getCardXProjection();
- var _loc6_ = this.testIntervals(p.bmin,p.bmax,this.minX,this.maxX);
- if(_loc6_ == 0)
- {
- return false;
- }
- p.getCardYProjection();
- var _loc5_ = this.testIntervals(p.bmin,p.bmax,this.minY,this.maxY);
- if(_loc5_ == 0)
- {
- return false;
- }
- var _loc11_ = Math.abs(_loc6_) < p.radius;
- var _loc12_ = Math.abs(_loc5_) < p.radius;
- if(_loc11_ && _loc12_)
- {
- var _loc10_ = this.center.x + this.sign(p.curr.x - this.center.x) * (this.rectWidth / 2);
- var _loc9_ = this.center.y + this.sign(p.curr.y - this.center.y) * (this.rectHeight / 2);
- var _loc4_ = p.curr.x - _loc10_;
- var _loc3_ = p.curr.y - _loc9_;
- var _loc8_ = Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_);
- var _loc7_ = p.radius - _loc8_;
- if(_loc7_ > 0)
- {
- _loc4_ /= _loc8_;
- _loc3_ /= _loc8_;
- p.mtd.setTo(_loc4_ * _loc7_,_loc3_ * _loc7_);
- this.normal.setTo(_loc4_,_loc3_);
- return true;
- }
- return false;
- }
- p.setXYMTD(_loc6_,_loc5_);
- this.normal.setTo(p.mtd.x / Math.abs(_loc6_),p.mtd.y / Math.abs(_loc5_));
- return true;
- }
- function isRectangleColliding(p)
- {
- p.getCardXProjection();
- var _loc4_ = this.testIntervals(p.bmin,p.bmax,this.minX,this.maxX);
- if(_loc4_ == 0)
- {
- return false;
- }
- p.getCardYProjection();
- var _loc3_ = this.testIntervals(p.bmin,p.bmax,this.minY,this.maxY);
- if(_loc3_ == 0)
- {
- return false;
- }
- p.setXYMTD(_loc4_,_loc3_);
- this.normal.setTo(p.mtd.x / Math.abs(_loc4_),p.mtd.y / Math.abs(_loc3_));
- return true;
- }
- function sign(val)
- {
- if(val < 0)
- {
- return -1;
- }
- if(val > 0)
- {
- return 1;
- }
- }
- }
-