public abstract class Hitbox
extends java.lang.Object
A Hitbox is a region of space that can be checked for intersection with other regions. A Hitbox has a position at a single point that acts as an origin point for the Hitbox's shape. This point is usually inside the Hitbox, but may not always be. Hitboxes can be rotated around their positions and flipped across horizontal and vertical axes through their positions. Rotating a Hitbox will also rotate the axes along which it is flipped. As with CellVectors, Hitboxes measure angles in degrees going counterclockwise from directly right and normalize them to be between 0 and 360.
If a Hitbox is a component of a CompositeHitbox, its position, flipped status, and angle of rotation are all relative to those of the CompositeHitbox. The same is true of a Hitbox being used by a SpaceObject, but not as its locator Hitbox, in relation to that SpaceObject's locator Hitbox. To avoid confusion, all spatial information about a Hitbox is specified as relative or absolute. For Hitboxes which are not located relative to other Hitboxes in this way, the two types of information are identical.
A Hitbox stores information on whether its surfaces in each Direction are solid, but this only affects its behavior when being used as a SpaceObject's solid Hitbox.
SpaceObject
,
CompositeHitbox
Constructor and Description 

Hitbox(CellVector relPosition)
Constructs a Hitbox with the specified relative position.

Hitbox(long relX,
long relY)
Constructs a Hitbox with the specified relative position.

Modifier and Type  Method and Description 

double 
angleTo(Hitbox hitbox)
Returns the absolute angle from this Hitbox's position to the specified
Hitbox's position.

void 
changeRelAngle(double relAngle)
Changes this Hitbox's relative angle of rotation by the specified amount.

void 
changeRelPosition(CellVector change)
Changes this Hitbox's relative position by the specified amount.

void 
changeRelPosition(long changeX,
long changeY)
Changes the coordinates of this Hitbox's relative position by the
specified amounts.

void 
changeRelX(long changeX)
Changes the xcoordinate of this Hitbox's relative position by the
specified amount.

void 
changeRelY(long changeY)
Changes the ycoordinate of this Hitbox's relative position by the
specified amount.

long 
distanceTo(Hitbox hitbox)
Returns the absolute distance from this Hitbox's position to the
specified Hitbox's position.

double 
getAbsAngle()
Returns this Hitbox's absolute angle of rotation.

long 
getAbsAngleX()
Returns the xcoordinate of the unit vector that points in the direction
of this Hitbox's absolute angle of rotation.

long 
getAbsAngleY()
Returns the ycoordinate of the unit vector that points in the direction
of this Hitbox's absolute angle of rotation.

CellVector 
getAbsPosition()
Returns this Hitbox's absolute position.

long 
getAbsX()
Returns the xcoordinate of this Hitbox's absolute position.

boolean 
getAbsXFlip()
Returns whether this Hitbox is absolutely horizontally flipped.

int 
getAbsXSign()
Returns 1 if this Hitbox is absolutely horizontally flipped and 1 if it
is not.

long 
getAbsY()
Returns the ycoordinate of this Hitbox's absolute position.

boolean 
getAbsYFlip()
Returns whether this Hitbox is absolutely vertically flipped.

int 
getAbsYSign()
Returns 1 if this Hitbox is absolutely vertically flipped and 1 if it is
not.

abstract long 
getBottomEdge()
Returns the ycoordinate of this Hitbox's absolute bottom boundary.

CompositeHitbox 
getComponentOf()
Returns the CompositeHitbox that this Hitbox is a component of, or null
if it is not a component of one.

abstract Hitbox 
getCopy()
Returns a copy of this Hitbox with its relative position at the origin
that is not flipped or rotated.

SpaceState 
getGameState()
Returns the SpaceState of the SpaceObject that is using this Hitbox, or
null if either the SpaceObject is not assigned to a SpaceState or this
Hitbox is not being used by a SpaceObject.

long 
getHeight()
Returns the difference between the ycoordinates of this Hitbox's
absolute bottom and top boundaries.

abstract long 
getLeftEdge()
Returns the xcoordinate of this Hitbox's absolute left boundary.

SpaceObject 
getObject()
Returns the SpaceObject that is using this Hitbox, directly or indirectly
as part of a CompositeHitbox, or null if it is not being used by a
SpaceObject.

double 
getRelAngle()
Returns this Hitbox's relative angle of rotation.

long 
getRelAngleX()
Returns the xcoordinate of the unit vector that points in the direction
of this Hitbox's relative angle of rotation.

long 
getRelAngleY()
Returns the ycoordinate of the unit vector that points in the direction
of this Hitbox's relative angle of rotation.

CellVector 
getRelPosition()
Returns this Hitbox's relative position.

long 
getRelX()
Returns the xcoordinate of this Hitbox's relative position.

boolean 
getRelXFlip()
Returns whether this Hitbox is relatively horizontally flipped.

int 
getRelXSign()
Returns 1 if this Hitbox is relatively horizontally flipped and 1 if it
is not.

long 
getRelY()
Returns the ycoordinate of this Hitbox's relative position.

boolean 
getRelYFlip()
Returns whether this Hitbox is relatively vertically flipped.

int 
getRelYSign()
Returns 1 if this Hitbox is relatively vertically flipped and 1 if it is
not.

abstract long 
getRightEdge()
Returns the xcoordinate of this Hitbox's absolute right boundary.

abstract long 
getTopEdge()
Returns the ycoordinate of this Hitbox's absolute top boundary.

long 
getWidth()
Returns the difference between the xcoordinates of this Hitbox's
absolute right and left boundaries.

boolean 
isSolid()
Returns whether any of this Hitbox's surfaces are solid.

static boolean 
overlap(Hitbox hitbox1,
Hitbox hitbox2)
Returns whether the two specified Hitboxes overlap.

boolean 
overlaps(Hitbox hitbox)
Returns whether this Hitbox overlaps the specified Hitbox.

void 
relFlipX()
Flips this Hitbox relatively horizontally, making it flipped if it was
not before and not flipped if it was before.

void 
relFlipY()
Flips this Hitbox relatively vertically, making it flipped if it was not
before and not flipped if it was before.

void 
setRelAngle(double relAngle)
Sets this Hitbox's relative angle of rotation to the specified value.

void 
setRelPosition(CellVector relPosition)
Sets this Hitbox's relative position to the specified value.

void 
setRelPosition(long relX,
long relY)
Sets this Hitbox's relative position to the specified coordinates.

void 
setRelX(long relX)
Sets the xcoordinate of this Hitbox's relative position to the specified
value.

void 
setRelXFlip(boolean relXFlip)
Sets whether this Hitbox is relatively horizontally flipped.

void 
setRelY(long relY)
Sets the ycoordinate of this Hitbox's relative position to the specified
value.

void 
setRelYFlip(boolean relYFlip)
Sets whether this Hitbox is relatively vertically flipped.

void 
setSolid(boolean solid)
Sets whether this Hitbox's surfaces in every direction are solid.

void 
setSurfaceSolid(Direction direction,
boolean solid)
Sets whether this Hitbox's surface in the specified Direction is solid.

boolean 
surfaceIsSolid(Direction direction)
Returns whether this Hitbox's surface in the specified Direction is
solid.

public Hitbox(CellVector relPosition)
relPosition
 This Hitbox's relative positionpublic Hitbox(long relX, long relY)
relX
 The xcoordinate of this Hitbox's relative positionrelY
 The ycoordinate of this Hitbox's relative positionpublic abstract Hitbox getCopy()
public final CompositeHitbox getComponentOf()
public final boolean isSolid()
public final boolean surfaceIsSolid(Direction direction)
direction
 The Direction of the surface to examinepublic final void setSurfaceSolid(Direction direction, boolean solid)
direction
 The Direction of the surface whose solidity is to be setsolid
 Whether the surface in the specified Direction should be
solidpublic final void setSolid(boolean solid)
solid
 Whether this Hitbox's surfaces in every direction should be
solidpublic final SpaceObject getObject()
public final SpaceState getGameState()
public final CellVector getRelPosition()
public final long getRelX()
public final long getRelY()
public final void setRelPosition(CellVector relPosition)
relPosition
 The new relative positionpublic final void setRelPosition(long relX, long relY)
relX
 The xcoordinate of the new relative positionrelY
 The ycoordinate of the new relative positionpublic final void setRelX(long relX)
relX
 The xcoordinate of the new relative positionpublic final void setRelY(long relY)
relY
 The ycoordinate of the new relative positionpublic final void changeRelPosition(CellVector change)
change
 The amount to change the relative position bypublic final void changeRelPosition(long changeX, long changeY)
changeX
 The amount to change the relative position's xcoordinate
bychangeY
 The amount to change the relative position's ycoordinate
bypublic final void changeRelX(long changeX)
changeX
 The amount to change the relative position's xcoordinate
bypublic final void changeRelY(long changeY)
changeY
 The amount to change the relative position's ycoordinate
bypublic final CellVector getAbsPosition()
public final long getAbsX()
public final long getAbsY()
public final boolean getRelXFlip()
public final int getRelXSign()
public final void setRelXFlip(boolean relXFlip)
relXFlip
 Whether this Hitbox should be relatively horizontally
flippedpublic final void relFlipX()
public final boolean getAbsXFlip()
public final int getAbsXSign()
public final boolean getRelYFlip()
public final int getRelYSign()
public final void setRelYFlip(boolean relYFlip)
relYFlip
 Whether this Hitbox should be relatively vertically
flippedpublic final void relFlipY()
public final boolean getAbsYFlip()
public final int getAbsYSign()
public final double getRelAngle()
public final long getRelAngleX()
public final long getRelAngleY()
public final void setRelAngle(double relAngle)
relAngle
 The new relative angle of rotationpublic final void changeRelAngle(double relAngle)
relAngle
 The amount to change the relative angle of rotation bypublic final double getAbsAngle()
public final long getAbsAngleX()
public final long getAbsAngleY()
public abstract long getLeftEdge()
public abstract long getRightEdge()
public abstract long getTopEdge()
public abstract long getBottomEdge()
public final long getWidth()
public final long getHeight()
public final long distanceTo(Hitbox hitbox)
hitbox
 The Hitbox to return the distance topublic final double angleTo(Hitbox hitbox)
hitbox
 The Hitbox to return the angle topublic final boolean overlaps(Hitbox hitbox)
hitbox
 The Hitbox to check for an overlappublic static boolean overlap(Hitbox hitbox1, Hitbox hitbox2)
hitbox1
 The first Hitboxhitbox2
 The second Hitbox