Пример #1
0
 /** @return the X collision offset */
 public final float getCollisionX() {
   if (isRound()) {
     return getRoundCollisionX();
   } else {
     getBounds(TEMP);
     return TEMP.getX() - getMapX() + TEMP.getWidth() * 0.5f;
   }
 }
Пример #2
0
 /** @return the Y collision offset */
 public final float getCollisionY() {
   if (isRound()) {
     return getRoundCollisionY();
   } else {
     getBounds(TEMP);
     return TEMP.getY() - getMapY() + TEMP.getHeight() * 0.5f;
   }
 }
Пример #3
0
  public void drawTile(Tile tile, int x, int y) {
    Rectangle spriteRegion = new Rectangle(x - xoffs + 16, y - yoffs + 16, 32, 32);

    if (screenRegion.contains(spriteRegion)) {
      g.drawImage(getTileSprite(tile.id), x - xoffs - 16, y - yoffs - 16);
    }
  }
Пример #4
0
  public void draw(Entity entity) {
    Rectangle spriteRegion =
        new Rectangle((int) (entity.x - xoffs + 16), (int) (entity.y - yoffs + 16), 32, 32);

    if (screenRegion.contains(spriteRegion)) {
      g.drawImage(
          getCharacterSprite(entity.id, entity.spritePos + entity.spriteDir * 3),
          (int) (entity.x) - xoffs - 16,
          (int) (entity.y) - yoffs - 16);
    }
  }
Пример #5
0
  public final boolean isTouching(ReadableRectangle rect) {
    if (isRound() && getRadius() == 0) {
      return false;
    }

    if (!isRound() && getBounds(BOUNDS).isEmpty()) {
      return false;
    }

    if (isRound()) {
      return rectRoundCollisionCheck(mapX, mapY, getRadius(), rect);
    } else {
      return BOUNDS.intersects(rect);
    }
  }
Пример #6
0
  /**
   * Are we touching a specific point?
   *
   * @param x
   * @param y
   * @return boolean
   */
  public final boolean isTouching(float x, float y) {
    if (isRound() && getRadius() == 0) {
      return false;
    }

    if (!isRound() && getBounds(BOUNDS).isEmpty()) {
      return false;
    }

    if (isRound()) {
      return getDistanceTo(x, y) < getRadius();
    } else {
      return BOUNDS.contains((int) x, (int) y);
    }
  }
Пример #7
0
  /**
   * Collision detection.
   *
   * @param dest The entity to check for collision with.
   * @return true if this entity is touching the destination entity; note that an entity can never
   *     be touching itself
   */
  public final boolean isTouching(Entity dest) {
    if (dest == this) {
      return false;
    }

    if (isRound() && getRadius() == 0) {
      return false;
    }

    if (dest.isRound() && dest.getRadius() == 0) {
      return false;
    }

    if (!isRound() && getBounds(BOUNDS).isEmpty()) {
      return false;
    }

    if (!dest.isRound() && dest.getBounds(TEMP).isEmpty()) {
      return false;
    }

    // At this point, BOUNDS and TEMP hold bounding rectangles, which we might
    // use if it's a rect-rect collision

    if (isRound() && dest.isRound()) {
      // Round-Round collision check
      float dx = dest.mapX + dest.getCollisionX() - (this.mapX + this.getCollisionX());
      float dy = dest.mapY + dest.getCollisionY() - (this.mapY + this.getCollisionY());
      dx *= dx;
      dy *= dy;

      return Math.sqrt(dx + dy) < getRadius() + dest.getRadius();
    } else if (isRound() && !dest.isRound()) {
      // Round-Rect collison check
      return rectRoundCollisionCheck(
          mapX + getCollisionX(), mapY + getCollisionY(), getRadius(), TEMP);
    } else if (!isRound() && dest.isRound()) {
      // Rect-round collision check
      return rectRoundCollisionCheck(
          dest.mapX + dest.getCollisionX(),
          dest.mapY + dest.getCollisionY(),
          dest.getRadius(),
          BOUNDS);
    } else {
      // Rect-rect collision check
      return BOUNDS.intersects(TEMP);
    }
  }