Class Hitbox
java.lang.Object
nl.saxion.gameapp.gameobject.hitbox.Hitbox
- Direct Known Subclasses:
CircleHitbox,PolygonHitbox,RectangleHitbox
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final GameObjectThe GameObject this hitbox belongs to. -
Constructor Summary
ConstructorsConstructorDescriptionHitbox(GameObject parent) Creates a new hitbox for the given parent GameObject. -
Method Summary
Modifier and TypeMethodDescriptionReturns the parent GameObject this hitbox belongs to.abstract booleanChecks if this hitbox overlaps with another hitbox.
-
Field Details
-
parent
The GameObject this hitbox belongs to.
-
-
Constructor Details
-
Hitbox
Creates a new hitbox for the given parent GameObject.- Parameters:
parent- the GameObject this hitbox is attached to
-
-
Method Details
-
getParent
Returns the parent GameObject this hitbox belongs to.- Returns:
- the parent GameObject
-
overlaps
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:
trueif this hitbox overlaps with the other,falseotherwise
-