Class Hitbox

java.lang.Object
nl.saxion.gameapp.gameobject.hitbox.Hitbox
Direct Known Subclasses:
CircleHitbox, PolygonHitbox, RectangleHitbox

public abstract class Hitbox extends Object
Represents a generic hitbox attached to a GameObject.

A hitbox defines the area of the object that can participate in collisions. Hitboxes can have different shapes (rectangle, circle, polygon, etc.) and are typically defined relative to the parent GameObject's position and size.

Subclasses must implement the overlaps(Hitbox) method to provide shape-specific collision detection with other hitboxes.

  • Field Details

    • parent

      protected final GameObject parent
      The GameObject this hitbox belongs to.
  • Constructor Details

    • Hitbox

      public Hitbox(GameObject parent)
      Creates a new hitbox for the given parent GameObject.
      Parameters:
      parent - the GameObject this hitbox is attached to
  • Method Details

    • getParent

      public GameObject getParent()
      Returns the parent GameObject this hitbox belongs to.
      Returns:
      the parent GameObject
    • overlaps

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

      Collision detection must be implemented by subclasses based on their specific shape. For example, a rectangle hitbox may use axis-aligned bounding box checks, while a polygon hitbox would use polygon collision detection.

      Parameters:
      other - the other hitbox to check collision against
      Returns:
      true if this hitbox overlaps with the other, false otherwise