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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(double x, double y) Checks if the hitbox contains a point.voiddrawDebug(processing.core.PGraphics buffer) Draws the hitbox with a debug color.voiddrawShape(processing.core.PGraphics buffer) Draws the shape.getShape()Returns the shape of the hitbox.booleanintersects(Hitbox hitbox) Checks if the hitbox intersects with another hitbox.voidtranslateAndRotateAndResize(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(double[] xPoints, double[] 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
-
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:
trueif the hitbox contains the point,falseotherwise.
-
getBounds
-
intersects
Checks if the hitbox intersects with another hitbox.- Parameters:
hitbox- The hitbox to check for intersection.- Returns:
trueif the hitboxes intersect,falseotherwise.
-
drawShape
public void drawShape(processing.core.PGraphics buffer) Draws the shape.- Parameters:
buffer- The buffer to draw the shape on.
-