Class CircleHitbox

java.lang.Object
nl.saxion.gameapp.gameobject.hitbox.Hitbox
nl.saxion.gameapp.gameobject.hitbox.CircleHitbox

public class CircleHitbox extends Hitbox
Represents a circular hitbox defined relative to the size of its parent GameObject.

The center is defined as a percentage of the parent width/height, and the radius is defined as a percentage of the smaller of the parent's width and height. This ensures proper scaling when the object is resized.

  • Constructor Details

    • CircleHitbox

      public CircleHitbox(GameObject parent, float relCenterX, float relCenterY, float relRadius)
      Creates a new circular hitbox relative to the parent GameObject.
      Parameters:
      parent - the GameObject this hitbox belongs to
      relCenterX - x-coordinate of the center as percentage of parent width
      relCenterY - y-coordinate of the center as percentage of parent height
      relRadius - radius as percentage of min(parent width, parent height)
  • Method Details

    • getAbsoluteCircle

      public com.badlogic.gdx.math.Circle getAbsoluteCircle()
      Returns the circle in absolute world coordinates, calculated from the parent GameObject's position and size.
      Returns:
      the circle in world coordinates
    • overlaps

      public boolean overlaps(Hitbox other)
      Checks if this hitbox overlaps another hitbox.

      Supports collisions with circles, rectangles, and polygons.

      Specified by:
      overlaps in class Hitbox
      Parameters:
      other - the other hitbox to check collision against
      Returns:
      true if the hitboxes overlap
    • getRelCenterX

      public float getRelCenterX()
    • getRelCenterY

      public float getRelCenterY()
    • getRelRadius

      public float getRelRadius()