Class Hitbox
java.lang.Object
org.openpatch.scratch.extensions.hitbox.Hitbox
Represents a hitbox with a shape that can be transformed by scaling, translating, and rotating
it.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(double x, double y) Checks if the hitbox contains a point.void
drawDebug
(processing.core.PGraphics buffer) Draws the hitbox with a debug color.void
drawShape
(processing.core.PGraphics buffer) Draws the shape.getShape()
Returns the shape of the hitbox.boolean
intersects
(Hitbox hitbox) Checks if the hitbox intersects with another hitbox.void
translateAndRotateAndResize
(double degrees, double originX, double originY, double translateX, double translateY, double size) Transforms the shape by scaling, translating, and rotating it.
-
Constructor Details
-
Hitbox
Constructs a hitbox with the specified shape.- Parameters:
shape
- The shape of the hitbox.
-
Hitbox
public Hitbox(int[] xPoints, int[] yPoints) Constructs a hitbox with the specified x and y points.- Parameters:
xPoints
- The x-coordinates of the points.yPoints
- The y-coordinates of the points.
-
-
Method Details
-
getShape
Returns the shape of the hitbox.- Returns:
- The shape of the hitbox.
-
translateAndRotateAndResize
public void translateAndRotateAndResize(double degrees, double originX, double originY, double translateX, double translateY, double size) Transforms the shape by scaling, translating, and rotating it.- Parameters:
degrees
- The angle in degrees to rotate the shape.originX
- The x-coordinate of the rotation origin.originY
- The y-coordinate of the rotation origin.translateX
- The x-coordinate to translate the shape.translateY
- The y-coordinate to translate the shape.size
- The size to scale the shape, where 100.0 represents the original size.
-
drawDebug
public void drawDebug(processing.core.PGraphics buffer) Draws the hitbox with a debug color.- Parameters:
buffer
- The buffer to draw the hitbox on.
-
contains
public boolean contains(double x, double y) Checks if the hitbox contains a point.- Parameters:
x
- The x-coordinate of the point.y
- The y-coordinate of the point.- Returns:
true
if the hitbox contains the point,false
otherwise.
-
intersects
Checks if the hitbox intersects with another hitbox.- Parameters:
hitbox
- The hitbox to check for intersection.- Returns:
true
if the hitboxes intersect,false
otherwise.
-
drawShape
public void drawShape(processing.core.PGraphics buffer) Draws the shape.- Parameters:
buffer
- The buffer to draw the shape on.
-