예제 #1
0
  public boolean checkCollide(Shape s) {
    int minXTile = (int) (s.getMinX()) / TILESIZE;
    int maxXTile = (int) (s.getMaxX()) / TILESIZE;
    int minYTile = (int) (s.getMinY()) / TILESIZE;
    int maxYTile = (int) (s.getMaxY()) / TILESIZE;

    for (int x = minXTile; x <= maxXTile; x++) {
      for (int y = minYTile; y <= maxYTile; y++) {
        if (tileIntegrity[x][y] > 0
            && s.intersects(new Rectangle(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE))) {
          return true;
        }
      }
    }

    return false;
  }
예제 #2
0
 public static Rectangle getNewBoundingRectangle(Shape shape) {
   if (shape instanceof Circle) {
     Circle circle = (Circle) shape;
     float x = circle.getCenterX();
     float y = circle.getCenterY();
     float r = circle.getRadius();
     return new Rectangle(x - r, y - r, 2 * r, 2 * r);
   }
   if (shape instanceof Line) {
     Line line = (Line) shape;
     float x1;
     float x2;
     if (line.getX2() > line.getX1()) {
       x1 = line.getX1();
       x2 = line.getX2();
     } else {
       x1 = line.getX2();
       x2 = line.getX1();
     }
     float y1;
     float y2;
     if (line.getY2() > line.getY1()) {
       y1 = line.getY1();
       y2 = line.getY2();
     } else {
       y1 = line.getY2();
       y2 = line.getY1();
     }
     return new Rectangle(
         x1 - EPSILON, y1 - EPSILON, x2 - x1 + 1 + EPSILON, y2 - y1 + 1 + EPSILON);
   }
   if (shape instanceof Rectangle) {
     Rectangle r = (Rectangle) shape;
     return new Rectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight());
   }
   assert false;
   return new Rectangle(shape.getMinX(), shape.getMinY(), shape.getWidth(), shape.getHeight());
 }