Class PolygonHitbox

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

public class PolygonHitbox extends Hitbox
Represents a polygon hitbox defined relative to the parent GameObject's size.

Vertices are stored as percentages of the parent width and height (0.0–1.0), allowing automatic scaling when the GameObject resizes. Supports arbitrary convex polygons and rotation.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     

    Fields inherited from class nl.saxion.gameapp.gameobject.hitbox.Hitbox

    parent
  • Constructor Summary

    Constructors
    Constructor
    Description
    PolygonHitbox(GameObject parent, float[] relVertices)
    Creates a new polygon hitbox relative to the parent GameObject.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.badlogic.gdx.math.Polygon
    Returns the polygon in absolute world coordinates, taking into account the parent GameObject's position and size.
    com.badlogic.gdx.math.Polygon
     
    float[]
     
    boolean
    Checks if this hitbox overlaps another hitbox.
    void
    setRotation(float degrees)
    Sets the rotation of the polygon hitbox.

    Methods inherited from class nl.saxion.gameapp.gameobject.hitbox.Hitbox

    getParent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PolygonHitbox

      public PolygonHitbox(GameObject parent, float[] relVertices)
      Creates a new polygon hitbox relative to the parent GameObject.
      Parameters:
      parent - the GameObject this hitbox belongs to
      relVertices - array of vertices (x1,y1,x2,y2,...) in 0–1 percentages
  • Method Details

    • setRotation

      public void setRotation(float degrees)
      Sets the rotation of the polygon hitbox.
      Parameters:
      degrees - rotation in degrees
    • getAbsolutePolygon

      public com.badlogic.gdx.math.Polygon getAbsolutePolygon()
      Returns the polygon in absolute world coordinates, taking into account the parent GameObject's position and size.
      Returns:
      polygon in world coordinates
    • overlaps

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

      Supports polygon-polygon, polygon-rectangle, and polygon-circle collisions.

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

      public com.badlogic.gdx.math.Polygon getPolygon()
    • getRelVertices

      public float[] getRelVertices()