home *** CD-ROM | disk | FTP | other *** search
/ Equipe de France et Bonbons / EquipeFrancePromoCD.iso / pages / cs_cadbury / loadergfx.swf / scripts / __Packages / PlayFieldRangeHandler.as < prev    next >
Encoding:
Text File  |  2006-03-19  |  6.8 KB  |  202 lines

  1. class PlayFieldRangeHandler
  2. {
  3.    var origin;
  4.    var length;
  5.    var width;
  6.    var topLeftPoint;
  7.    var topRightPoint;
  8.    var bottomRightPoint;
  9.    var bottomLeftPoint;
  10.    var centerX;
  11.    var centerY;
  12.    var leftCage_origin;
  13.    var leftCage_length;
  14.    var leftCage_width;
  15.    var leftCage_topLeft;
  16.    var leftCage_topRight;
  17.    var leftCage_bottomRight;
  18.    var leftCage_bottomLeft;
  19.    var leftCage_centerX;
  20.    var leftCage_centerY;
  21.    var rightCage_origin;
  22.    var rightCage_length;
  23.    var rightCage_width;
  24.    var rightCage_topLeft;
  25.    var rightCage_topRight;
  26.    var rightCage_bottomRight;
  27.    var rightCage_bottomLeft;
  28.    var rightCage_centerX;
  29.    var rightCage_centerY;
  30.    function PlayFieldRangeHandler(origin, length, width)
  31.    {
  32.       this.origin = origin;
  33.       this.length = length;
  34.       this.width = width;
  35.       this.topLeftPoint = new Point2D(this.origin.getX(),this.origin.getY());
  36.       this.topRightPoint = new Point2D(this.origin.getX() + this.length,this.origin.getY());
  37.       this.bottomRightPoint = new Point2D(this.origin.getX() + this.length,this.origin.getY() + this.width);
  38.       this.bottomLeftPoint = new Point2D(this.origin.getX(),this.origin.getY() + this.width);
  39.       this.centerX = Math.floor(this.origin.getX() + this.length / 2);
  40.       this.centerY = Math.floor(this.origin.getY() + this.width / 2);
  41.    }
  42.    function initLeftCage(origin, length, width)
  43.    {
  44.       this.leftCage_origin = origin;
  45.       this.leftCage_length = length;
  46.       this.leftCage_width = width;
  47.       this.leftCage_topLeft = new Point2D(this.leftCage_origin.getX(),this.leftCage_origin.getY());
  48.       this.leftCage_topRight = new Point2D(this.leftCage_origin.getX() + this.leftCage_length,this.leftCage_origin.getY());
  49.       this.leftCage_bottomRight = new Point2D(this.leftCage_origin.getX() + this.leftCage_length,this.leftCage_origin.getY() + this.leftCage_width);
  50.       this.leftCage_bottomLeft = new Point2D(this.leftCage_origin.getX(),this.leftCage_origin.getY() + this.leftCage_width);
  51.       this.leftCage_centerX = Math.floor(this.leftCage_origin.getX() + this.leftCage_length / 2);
  52.       this.leftCage_centerY = Math.floor(this.leftCage_origin.getY() + this.leftCage_width / 2);
  53.    }
  54.    function initRightCage(origin, length, width)
  55.    {
  56.       this.rightCage_origin = origin;
  57.       this.rightCage_length = length;
  58.       this.rightCage_width = width;
  59.       this.rightCage_topLeft = new Point2D(this.rightCage_origin.getX(),this.rightCage_origin.getY());
  60.       this.rightCage_topRight = new Point2D(this.rightCage_origin.getX() + this.rightCage_length,this.rightCage_origin.getY());
  61.       this.rightCage_bottomRight = new Point2D(this.rightCage_origin.getX() + this.rightCage_length,this.rightCage_origin.getY() + this.rightCage_width);
  62.       this.rightCage_bottomLeft = new Point2D(this.rightCage_origin.getX(),this.rightCage_origin.getY() + this.rightCage_width);
  63.       this.rightCage_centerX = Math.floor(this.rightCage_origin.getX() + this.rightCage_length / 2);
  64.       this.rightCage_centerY = Math.floor(this.rightCage_origin.getY() + this.rightCage_width / 2);
  65.    }
  66.    function getMinX()
  67.    {
  68.       return this.origin.getX();
  69.    }
  70.    function getMaxX()
  71.    {
  72.       return this.origin.getX() + this.length;
  73.    }
  74.    function getMinY()
  75.    {
  76.       return this.origin.getY();
  77.    }
  78.    function getMaxY()
  79.    {
  80.       return this.origin.getY() + this.width;
  81.    }
  82.    function getCenterX()
  83.    {
  84.       return this.centerX;
  85.    }
  86.    function getCenterY()
  87.    {
  88.       return this.centerY;
  89.    }
  90.    function getLenth()
  91.    {
  92.       return this.length;
  93.    }
  94.    function getWidth()
  95.    {
  96.       return this.width;
  97.    }
  98.    function testObjectInPlayField(x, y)
  99.    {
  100.       if(this.rightCage_origin == undefined)
  101.       {
  102.          trace("rightCage no initialised !");
  103.       }
  104.       var _loc2_ = Math.floor(x);
  105.       var _loc3_ = Math.floor(y);
  106.       if(_loc2_ > this.getMinX() && _loc2_ < this.getMaxX() && _loc3_ > this.getMinY() && _loc3_ < this.getMaxY())
  107.       {
  108.          return true;
  109.       }
  110.       return false;
  111.    }
  112.    function testObjectInRightCage(x, y)
  113.    {
  114.       if(this.rightCage_origin == undefined)
  115.       {
  116.          trace("rightCage no initialised !");
  117.       }
  118.       var _loc2_ = Math.floor(x);
  119.       var _loc3_ = Math.floor(y);
  120.       if(_loc2_ > this.rightCage_origin.getX() && _loc2_ < this.rightCage_origin.getX() + this.rightCage_length)
  121.       {
  122.          if(_loc3_ > this.rightCage_origin.getY() && _loc3_ < this.rightCage_origin.getY() + this.rightCage_width)
  123.          {
  124.             return true;
  125.          }
  126.       }
  127.       return false;
  128.    }
  129.    function testObjectInLeftCage(x, y)
  130.    {
  131.       if(this.leftCage_origin == undefined)
  132.       {
  133.          trace("leftCage no initialised !");
  134.       }
  135.       var _loc2_ = Math.floor(x);
  136.       var _loc3_ = Math.floor(y);
  137.       if(_loc2_ > this.leftCage_origin.getX() && _loc2_ < this.leftCage_origin.getX() + this.leftCage_length && _loc3_ > this.leftCage_origin.getY() && _loc3_ < this.leftCage_origin.getY() + this.leftCage_width)
  138.       {
  139.          return true;
  140.       }
  141.       return false;
  142.    }
  143.    function testObjectInTheDepthOfRightCage(x, y)
  144.    {
  145.       var _loc2_ = Math.floor(x);
  146.       var _loc3_ = Math.floor(y);
  147.       if(this.testObjectInRightCage(_loc2_,_loc3_) == false)
  148.       {
  149.          return false;
  150.       }
  151.       if(_loc2_ > this.rightCage_origin.getX() + 20)
  152.       {
  153.          return true;
  154.       }
  155.       return false;
  156.    }
  157.    function testObjectInTheDepthOfLeftCage(x, y)
  158.    {
  159.       var _loc2_ = Math.floor(x);
  160.       var _loc3_ = Math.floor(y);
  161.       if(this.testObjectInLeftCage(_loc2_,_loc3_) == false)
  162.       {
  163.          return false;
  164.       }
  165.       if(_loc2_ < this.leftCage_origin.getX() + 5)
  166.       {
  167.          return true;
  168.       }
  169.       return false;
  170.    }
  171.    function trace()
  172.    {
  173.       trace("Play Field Range:");
  174.       this.topLeftPoint.trace();
  175.       this.topRightPoint.trace();
  176.       this.bottomRightPoint.trace();
  177.       this.bottomLeftPoint.trace();
  178.       trace("Center(x,y) = (" + this.centerX + ", " + this.centerY + ")");
  179.       trace("-----------------");
  180.    }
  181.    function traceRightCage()
  182.    {
  183.       trace("---------------------------------");
  184.       trace("Right Cage:");
  185.       trace("Origine: ");
  186.       this.rightCage_origin.trace();
  187.       trace("Length: " + this.rightCage_length);
  188.       trace("Width: " + this.rightCage_width);
  189.       trace("Top Left: ");
  190.       this.rightCage_topLeft.trace();
  191.       trace("Top Right: ");
  192.       this.rightCage_topRight.trace();
  193.       trace("Bottom Right: ");
  194.       this.rightCage_bottomRight.trace();
  195.       trace("Bottom Left: ");
  196.       this.rightCage_bottomLeft.trace();
  197.       trace("Center X: " + this.rightCage_centerX);
  198.       trace("Center Y: " + this.rightCage_centerY);
  199.       trace("---------------------------------");
  200.    }
  201. }
  202.