예제 #1
0
 public static boolean internalIntersects(Shape shape1, Shape shape2) {
   TimingInfo.CURRENT_TIMING_INFO.getCounter("GeometryUtils.intersects").record(1);
   if (shape1.intersects(shape2)) return true;
   if ((shape1 instanceof Rectangle && shape2 instanceof Circle)
       || (shape2 instanceof Rectangle && shape1 instanceof Circle)) {
     Circle c;
     Rectangle r;
     if (shape1 instanceof Circle) {
       c = (Circle) shape1;
       r = (Rectangle) shape2;
     } else {
       c = (Circle) shape2;
       r = (Rectangle) shape1;
     }
     if (r.contains(c.getCenterX(), c.getCenterY())) {
       return true;
     }
   }
   if (shape2 instanceof Line) {
     return shape1.contains(shape2);
   }
   if (shape1 instanceof Line) {
     return shape2.contains(shape1);
   }
   return false;
 }
  public void drawCircle(int xPos, int yPos, int radius, int id) {

    // c.setLocation(xPos, yPos);
    c.setCenterX(xPos);
    c.setCenterY(yPos);
    c.setRadius(radius);

    drawableMap.updateBlocks(c, id);
  }
예제 #3
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());
 }
예제 #4
0
  @Override
  public void update(Level level, GameContainer arg0) {
    if (shownFor >= 50) {
      shownFor = 0;
      if (pos != colors.length - 1) {
        pos++;
      } else {
        pos = 0;
      }
    }
    if (AOE) {
      if (AOEShape == null) {
        AOERadius = 4.0f;
        AOEShape =
            new Circle(this.getShape().getCenterX(), this.getShape().getCenterY(), AOERadius);

      } else {
        AOERadius += 4f;
        AOEShape.setRadius(AOERadius);
        AOEShape.setCenterX(this.getShape().getCenterX());
        AOEShape.setCenterY(this.getShape().getCenterY());
      }

      if (AOERadius >= 300) {
        AOE = false;
        AOEShape = null;
        AOERadius = 0.0f;
      }

      for (Entity e : level.entitys) {
        if (AOEShape == null) break;
        if (e.getShape().intersects(AOEShape)) {
          e.die(level);
        }
      }
    }
  }