Package nl.saxion.gameapp.gameobject
Class RotatableGameObject
java.lang.Object
nl.saxion.gameapp.gameobject.GameObject
nl.saxion.gameapp.gameobject.RotatableGameObject
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 Summary
FieldsModifier and TypeFieldDescriptionprotected floatRotation of the object in degrees (0 = no rotation, positive = clockwise). -
Constructor Summary
ConstructorsConstructorDescriptionRotatableGameObject(float x, float y, float width, float height) Creates a new RotatableGameObject. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHitbox(float relOffsetX, float relOffsetY, float relWidth, float relHeight) Adds a rectangular hitbox in relative percentages.voidAdds a hitbox to this RotatableGameObject.floatReturns the current rotation of the object in degrees.voidsetRotation(float rotation) Sets the rotation of the object in degrees.Methods inherited from class nl.saxion.gameapp.gameobject.GameObject
addCircleHitbox, addPolygonHitbox, centerOn, collidesWith, contains, directionTo, distanceTo, drawHitboxes, getBottomLeft, getBottomRight, getBounds, getCenterPoint, getCenterX, getCenterY, getHeight, getHitboxes, getTopLeft, getTopRight, getWidth, getX, getY, moveBy, moveTo, render, setHeight, setWidth, setX, setY
-
Field Details
-
rotation
protected float rotationRotation 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-coordinatey- initial y-coordinatewidth- width of the objectheight- 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
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:
addHitboxin classGameObject- 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:
addHitboxin classGameObject- Parameters:
relOffsetX- x-offset as percentage of widthrelOffsetY- y-offset as percentage of heightrelWidth- width as percentage of widthrelHeight- height as percentage of height
-