Package com.dragonboatrace.tools
Class Hitbox
- java.lang.Object
-
- com.dragonboatrace.tools.Hitbox
-
public class Hitbox extends java.lang.Object
Represents an Entities Hitbox.
-
-
Constructor Summary
Constructors Constructor Description Hitbox(float x, float y, int width, int height)
Create a new hit box at a specified position with a width and height.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
collidesWith(Hitbox box)
Check if the hit box is colliding with another hit box.int
getHeight()
Get the height of the hit box.int
getWidth()
Get the width of the hit box.float
getX()
Get the x coordinate of the hit box.float
getY()
Get the y coordinate of the hit box.boolean
leaves(Hitbox box)
Checks if the another hit box has left the area of this hit box.void
move(float x, float y)
Move the hit box's position to the one specified, not additive.
-
-
-
Constructor Detail
-
Hitbox
public Hitbox(float x, float y, int width, int height)
Create a new hit box at a specified position with a width and height.- Parameters:
x
- The x position of the bottom left corner.y
- The y position of the bottom left corner.width
- The width of the hit box.height
- The height of the hit box
-
-
Method Detail
-
move
public void move(float x, float y)
Move the hit box's position to the one specified, not additive.Used to make sure the hit boxes position is the same as the entity it represents.
- Parameters:
x
- The new x position.y
- The new y position.
-
collidesWith
public boolean collidesWith(Hitbox box)
Check if the hit box is colliding with another hit box.- Parameters:
box
- The hit box that the collision is being checked against.- Returns:
- A boolean of if the two hit boxes are intersecting.
-
leaves
public boolean leaves(Hitbox box)
Checks if the another hit box has left the area of this hit box.- Parameters:
box
- The other hit box.- Returns:
- A boolean of if the other hit box is partially outside of this hit box
-
getX
public float getX()
Get the x coordinate of the hit box.- Returns:
- A float of the x position of the bottom left corner.
-
getY
public float getY()
Get the y coordinate of the hit box.- Returns:
- A float of the y position of the bottom left corner.
-
getWidth
public int getWidth()
Get the width of the hit box.- Returns:
- An int representing how wide the hit box is.
-
getHeight
public int getHeight()
Get the height of the hit box.- Returns:
- An int representing how tall the hit box is.
-
-