Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
  // propagate logic
  public void moveBullet(float ms) {
    // the bigger amount of pixels to move.
    float steps =
        (Math.abs(xVel * ms) > Math.abs(yVel * ms)) ? Math.abs(xVel * ms) : Math.abs(yVel * ms);

    steps += 1;

    float deltaX = (xVel * ms) / steps;
    float deltaY = (yVel * ms) / steps;

    for (int i = 0; i != (int) (steps + 1); i++) {
      shape.setX(shape.getX() + deltaX);
      shape.setY(shape.getY() + deltaY);

      for (SPlayer p : SState.players) {

        if (p != null) {
          if (p.intersects(shape)) {
            p.hurt(damage);
            live = false;
            return;
          }
        }
      }

      if (SState.map.checkCollide(getShape())) {
        live = false;
        return;
      }
    }
  }
Ejemplo n.º 3
0
 public Enemy(Image image, Vector2f location) {
   this.image = image;
   loc = location;
   collisionRect = new Rectangle(0, 0, image.getWidth(), image.getHeight());
   collisionRect.setCenterX(loc.x);
   collisionRect.setCenterY(loc.y);
   isDead = false;
 }
Ejemplo n.º 4
0
 /**
  * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
  *     org.newdawn.slick.Graphics)
  */
 public void render(GUIContext container, Graphics g) {
   if (currentImage != null) {
     currentImage.draw(area.getX(), area.getY(), currentColor);
   } else {
     g.setColor(currentColor);
     g.fill(area);
   }
   updateImage();
 }
Ejemplo n.º 5
0
 private float randomX(GameContainer c, Shape s) throws MushroomFactoryException {
   float x = -1;
   int numTries = 0;
   while (x < 0 || x >= c.getWidth()) {
     x = (float) (s.getMaxX() - s.getX() * Math.random());
     x += s.getX();
     numTries++;
     if (numTries > 6) {
       throw new MushroomFactoryException("Can't find valid point.");
     }
   }
   return x;
 }
Ejemplo n.º 6
0
 private float randomY(GameContainer c, Shape s) throws MushroomFactoryException {
   float y = -1;
   int numTries = 0;
   while (y < 0 || y >= c.getHeight()) {
     y = (float) (s.getMaxY() - s.getY() * Math.random());
     y += s.getY();
     numTries++;
     if (numTries > 6) {
       throw new MushroomFactoryException("Can't find valid point.");
     }
   }
   return y;
 }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  public boolean colliding(AEntity entity) {

    if (shape != null && entity.shape != null) {
      return shape.intersects(entity.shape);
    }

    return false;
  }
Ejemplo n.º 9
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());
 }
Ejemplo n.º 10
0
  /**
   * Create a new mouse over area
   *
   * @param container The container displaying the mouse over area
   * @param image The normalImage to display
   * @param shape The shape defining the area of the mouse sensitive zone
   */
  public MouseOverArea(GUIContext container, Image image, Shape shape) {
    super(container);

    area = shape;
    normalImage = image;
    currentImage = image;
    mouseOverImage = image;
    mouseDownImage = image;

    currentColor = normalColor;

    state = NORMAL;
    Input input = container.getInput();
    over = area.contains(input.getMouseX(), input.getMouseY());
    mouseDown = input.isMouseButtonDown(0);
    updateImage();
  }
Ejemplo n.º 11
0
  public void mouseClicked(int na, int x, int y, int clickCount) {
    for (MKSpriteNode node : buttons) {
      for (MKPhysicsBody body : node.getPhysicsBodies()) {
        Shape rigidBody = body.getBody();
        if (rigidBody.contains(mouseShape) || rigidBody.intersects(mouseShape))
          this.setDisplayTo(node);
      }
    }

    for (MKPhysicsBody body : playButton.getPhysicsBodies()) {
      Shape rigidBody = body.getBody();
      if (rigidBody.contains(mouseShape) || rigidBody.intersects(mouseShape))
        this.moveToGameWithPlayer(displayRacer);
    }
  }
Ejemplo n.º 12
0
 /** @see org.newdawn.slick.gui.AbstractComponent#getHeight() */
 public int getHeight() {
   return (int) (area.getMaxY() - area.getY());
 }
Ejemplo n.º 13
0
 /** @see org.newdawn.slick.util.InputAdapter#mouseReleased(int, int, int) */
 public void mouseReleased(int button, int mx, int my) {
   over = area.contains(mx, my);
   if (button == 0) {
     mouseDown = false;
   }
 }
Ejemplo n.º 14
0
 /** @see org.newdawn.slick.util.InputAdapter#mousePressed(int, int, int) */
 public void mousePressed(int button, int mx, int my) {
   over = area.contains(mx, my);
   if (button == 0) {
     mouseDown = true;
   }
 }
Ejemplo n.º 15
0
 /** @see org.newdawn.slick.util.InputAdapter#mouseMoved(int, int, int, int) */
 public void mouseMoved(int oldx, int oldy, int newx, int newy) {
   over = area.contains(newx, newy);
 }
Ejemplo n.º 16
0
 /**
  * Returns the position in the Y coordinate
  *
  * @return y
  */
 public int getY() {
   return (int) area.getY();
 }
Ejemplo n.º 17
0
 /**
  * Moves the component.
  *
  * @param x X coordinate
  * @param y Y coordinate
  */
 public void setLocation(float x, float y) {
   if (area != null) {
     area.setX(x);
     area.setY(y);
   }
 }
Ejemplo n.º 18
0
  /**
   * "locks the camera on the center of the given Shape. The camera
   *
   * <p>tries to keep the location in its center.
   *
   * @param shape the Shape which should be centered on the screen
   */
  public void centerOn(Shape shape) {

    this.centerOn(shape.getCenterX(), shape.getCenterY());
  }
Ejemplo n.º 19
0
 /** @see org.newdawn.slick.gui.AbstractComponent#getWidth() */
 public int getWidth() {
   return (int) (area.getMaxX() - area.getX());
 }
Ejemplo n.º 20
0
 /**
  * Set the x coordinate of this area
  *
  * @param x The new x coordinate of this area
  */
 public void setX(float x) {
   area.setX(x);
 }
Ejemplo n.º 21
0
 public static float getMaxY(Shape rectangle) {
   return rectangle.getY() + rectangle.getHeight() - 1;
 }
Ejemplo n.º 22
0
 public Shape getShape() {
   Shape shape = new Rectangle(0, 0, Car.width, Car.height);
   shape.setLocation(lastKnownPosition);
   return shape;
 }
Ejemplo n.º 23
0
 /**
  * Set the y coordinate of this area
  *
  * @param y The new y coordinate of this area
  */
 public void setY(float y) {
   area.setY(y);
 }
Ejemplo n.º 24
0
 public void setSize(int width, int height) {
   Shape shape = new Rectangle(area.getX(), area.getY(), width, height);
   this.area = shape;
 }
Ejemplo n.º 25
0
 public static float getMaxX(Shape rectangle) {
   return rectangle.getX() + rectangle.getWidth() - 1;
 }