Class RotatableGameObject

java.lang.Object
nl.saxion.gameapp.gameobject.GameObject
nl.saxion.gameapp.gameobject.RotatableGameObject

public abstract class RotatableGameObject extends GameObject
Extends GameObject to support rotation.

Rectangular hitboxes are automatically converted into polygons to allow accurate collision detection with rotation. Circle hitboxes remain unchanged. This class does not include movement or update logic; rotation must be managed manually.

  • Field Details

    • rotation

      protected float rotation
      Rotation of the object in degrees (0 = no rotation, positive = clockwise).
  • Constructor Details

    • RotatableGameObject

      public RotatableGameObject(float x, float y, float width, float height)
      Creates a new RotatableGameObject.
      Parameters:
      x - initial x-coordinate
      y - initial y-coordinate
      width - width of the object
      height - height of the object
  • Method Details

    • getRotation

      public float getRotation()
      Returns the current rotation of the object in degrees.
      Returns:
      rotation in degrees
    • setRotation

      public void setRotation(float rotation)
      Sets the rotation of the object in degrees.
      Parameters:
      rotation - new rotation in degrees
    • addHitbox

      public void addHitbox(Hitbox hitbox)
      Adds a hitbox to this RotatableGameObject.

      If the hitbox is a rectangle, it will automatically be converted into a polygon, so that rotation and collision detection work correctly.

      Overrides:
      addHitbox in class GameObject
      Parameters:
      hitbox - the hitbox to add
    • addHitbox

      public void addHitbox(float relOffsetX, float relOffsetY, float relWidth, float relHeight)
      Adds a rectangular hitbox in relative percentages. Automatically converted to polygon.
      Overrides:
      addHitbox in class GameObject
      Parameters:
      relOffsetX - x-offset as percentage of width
      relOffsetY - y-offset as percentage of height
      relWidth - width as percentage of width
      relHeight - height as percentage of height