home *** CD-ROM | disk | FTP | other *** search
- class org.cove.flade.surfaces.RectangleTile extends org.cove.flade.surfaces.AbstractTile implements org.cove.flade.surfaces.Surface
- {
- var rectWidth;
- var rectHeight;
- var isVisible;
- var dmc;
- var center;
- var normal;
- var minX;
- var maxX;
- var minY;
- var maxY;
- function RectangleTile(cx, cy, rw, rh, rootmc)
- {
- super(cx,cy,rootmc);
- this.rectWidth = rw;
- this.rectHeight = rh;
- this.createBoundingRect(rw,rh);
- }
- function paint()
- {
- if(this.isVisible)
- {
- this.dmc.clear();
- this.dmc.lineStyle(0,2237064,100);
- org.cove.flade.graphics.Graphics.paintRectangle(this.dmc,this.center.x,this.center.y,this.rectWidth,this.rectHeight);
- }
- }
- function resolveCircleCollision(p, sysObj)
- {
- if(this.isCircleColliding(p))
- {
- this.onContact();
- p.resolveCollision(this.normal,sysObj);
- p.SetCollision();
- }
- }
- function resolveRectangleCollision(p, sysObj)
- {
- if(this.isRectangleColliding(p))
- {
- this.onContact();
- p.resolveCollision(this.normal,sysObj);
- p.SetCollision();
- }
- }
- 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;
- }
- }
- }
-