T
- The subclass of CellGame that uses the SpaceStates that can use
this PolygonHitboxpublic class PolygonHitbox<T extends CellGame> extends Hitbox<T>
A PolygonHitbox is a polygonal Hitbox defined by a List of vertices. A PolygonHitbox occupies the area enclosed by a loop of line segments between each of its vertices and the next, and between the first and last vertices. It is the responsibility of the creators and modifiers of a PolygonHitbox to ensure that its vertices are not positioned in such a way that this loop crosses itself. Both relative and absolute vertices are relative to their PolygonHitbox's position. A PolygonHitbox with no vertices is a point at its absolute position.
Constructor and Description |
---|
PolygonHitbox(CellVector relPosition)
Creates a new PolygonHitbox with the specified relative position and no
vertices.
|
PolygonHitbox(CellVector relPosition,
CellVector[] relVertices)
Creates a new PolygonHitbox with the specified relative position and
vertices.
|
PolygonHitbox(long relX,
long relY)
Creates a new PolygonHitbox with the specified relative position and no
vertices.
|
PolygonHitbox(long relX,
long relY,
CellVector[] relVertices)
Creates a new PolygonHitbox with the specified relative position and
vertices.
|
Modifier and Type | Method and Description |
---|---|
void |
addRelVertex(int index,
CellVector relVertex)
Adds the specified relative vertex to this PolygonHitbox at the specified
index.
|
void |
addRelVertex(int index,
long relX,
long relY)
Adds the specified relative vertex to this PolygonHitbox at the specified
index.
|
void |
addVertex(CellVector relVertex)
Adds the specified relative vertex to this PolygonHitbox at the index
after its last one, between its last and first relative vertices.
|
void |
addVertex(long relX,
long relY)
Adds the specified relative vertex to this PolygonHitbox at the index
after its last one, between its last and first relative vertices.
|
void |
clearVertices()
Removes all of this PolygonHitbox's vertices.
|
CellVector |
getAbsVertex(int index)
Returns this PolygonHitbox's absolute vertex at the specified index.
|
long |
getAbsVertexX(int index)
Returns the x-coordinate of this PolygonHitbox's absolute vertex at the
specified index.
|
long |
getAbsVertexY(int index)
Returns the y-coordinate of this PolygonHitbox's absolute vertex at the
specified index.
|
java.util.List<CellVector> |
getAbsVertices()
Returns the List of this PolygonHitbox's absolute vertices.
|
long |
getBottomEdge()
Returns the y-coordinate of this Hitbox's absolute bottom boundary.
|
Hitbox<T> |
getCopy()
Returns a copy of this Hitbox with its relative position at the origin
that is not flipped or rotated.
|
long |
getLeftEdge()
Returns the x-coordinate of this Hitbox's absolute left boundary.
|
int |
getNumVertices()
Returns how many vertices this PolygonHitbox has.
|
CellVector |
getRelVertex(int index)
Returns this PolygonHitbox's relative vertex at the specified index.
|
long |
getRelVertexX(int index)
Returns the x-coordinate of this PolygonHitbox's relative vertex at the
specified index.
|
long |
getRelVertexY(int index)
Returns the y-coordinate of this PolygonHitbox's relative vertex at the
specified index.
|
java.util.List<CellVector> |
getRelVertices()
Returns the List of this PolygonHitbox's relative vertices.
|
long |
getRightEdge()
Returns the x-coordinate of this Hitbox's absolute right boundary.
|
long |
getTopEdge()
Returns the y-coordinate of this Hitbox's absolute top boundary.
|
static PolygonHitbox |
regularPolygon(long relX,
long relY,
int numVertices,
long radius,
double angle)
Returns a new PolygonHitbox in the shape of a regular polygon.
|
void |
removeVertex(int index)
Removes this PolygonHitbox's vertex at the specified index.
|
void |
scale(long scaleFactor)
Multiplies the coordinates of all of this PolygonHitbox's relative
vertices by the specified factor.
|
void |
setRelVertex(int index,
CellVector relVertex)
Sets this PolygonHitbox's relative vertex at the specified index to the
specified value.
|
void |
setRelVertex(int index,
long relX,
long relY)
Sets this PolygonHitbox's relative vertex at the specified index to the
specified value.
|
void |
setRelVertexX(int index,
long relX)
Sets the x-coordinate of this PolygonHitbox's relative vertex at the
specified index to the specified value.
|
void |
setRelVertexY(int index,
long relY)
Sets the y-coordinate of this PolygonHitbox's relative vertex at the
specified index to the specified value.
|
angleTo, changeRelAngle, changeRelPosition, changeRelPosition, changeRelX, changeRelY, distanceTo, getAbsAngle, getAbsAngleX, getAbsAngleY, getAbsPosition, getAbsX, getAbsXFlip, getAbsXSign, getAbsY, getAbsYFlip, getAbsYSign, getComponentOf, getGameState, getObject, getRelAngle, getRelAngleX, getRelAngleY, getRelPosition, getRelX, getRelXFlip, getRelXSign, getRelY, getRelYFlip, getRelYSign, isSolid, overlap, overlaps, relFlipX, relFlipY, setRelAngle, setRelPosition, setRelPosition, setRelX, setRelXFlip, setRelY, setRelYFlip, setSolid, setSurfaceSolid, surfaceIsSolid
public PolygonHitbox(CellVector relPosition, CellVector[] relVertices)
relPosition
- This PolygonHitbox's relative positionrelVertices
- This PolygonHitbox's relative verticespublic PolygonHitbox(long relX, long relY, CellVector[] relVertices)
relX
- The x-coordinate of this PolygonHitbox's relative positionrelY
- The y-coordinate of this PolygonHitbox's relative positionrelVertices
- This PolygonHitbox's relative verticespublic PolygonHitbox(CellVector relPosition)
relPosition
- This PolygonHitbox's relative positionpublic PolygonHitbox(long relX, long relY)
relX
- The x-coordinate of this PolygonHitbox's relative positionrelY
- The y-coordinate of this PolygonHitbox's relative positionpublic static final PolygonHitbox regularPolygon(long relX, long relY, int numVertices, long radius, double angle)
relX
- The x-coordinate of the new PolygonHitbox's relative positionrelY
- The y-coordinate of the new PolygonHitbox's relative positionnumVertices
- The new PolygonHitbox's number of vertices. This must
be at least 3.radius
- The distance from the new PolygonHitbox's position to each
of its verticesangle
- The angle from the origin to the new PolygonHitbox's first
relative vertexpublic Hitbox<T> getCopy()
Hitbox
public final java.util.List<CellVector> getRelVertices()
public final java.util.List<CellVector> getAbsVertices()
public final int getNumVertices()
public final CellVector getRelVertex(int index)
index
- The index of the relative vertexpublic final long getRelVertexX(int index)
index
- The index of the relative vertexpublic final long getRelVertexY(int index)
index
- The index of the relative vertexpublic final CellVector getAbsVertex(int index)
index
- The index of the absolute vertexpublic final long getAbsVertexX(int index)
index
- The index of the absolute vertexpublic final long getAbsVertexY(int index)
index
- The index of the absolute vertexpublic final void addVertex(CellVector relVertex)
relVertex
- The new relative vertexpublic final void addVertex(long relX, long relY)
relX
- The x-coordinate of the new relative vertexrelY
- The y-coordinate of the new relative vertexpublic final void addRelVertex(int index, CellVector relVertex)
index
- The index at which to add the new relative vertexrelVertex
- The new relative vertexpublic final void addRelVertex(int index, long relX, long relY)
index
- The index at which to add the new relative vertexrelX
- The x-coordinate of the new relative vertexrelY
- The y-coordinate of the new relative vertexpublic final void setRelVertex(int index, CellVector relVertex)
index
- The index of the relative vertex to be changedrelVertex
- The new relative vertexpublic final void setRelVertex(int index, long relX, long relY)
index
- The index of the relative vertex to be changedrelX
- The x-coordinate of the new relative vertexrelY
- The y-coordinate of the new relative vertexpublic final void setRelVertexX(int index, long relX)
index
- The index of the relative vertex to be changedrelX
- The relative vertex's new x-coordinatepublic final void setRelVertexY(int index, long relY)
index
- The index of the relative vertex to be changedrelY
- The relative vertex's new y-coordinatepublic final void removeVertex(int index)
index
- The index of the vertex to be removedpublic final void clearVertices()
public final void scale(long scaleFactor)
scaleFactor
- The factor by which to scale this PolygonHitboxpublic final long getLeftEdge()
Hitbox
getLeftEdge
in class Hitbox<T extends CellGame>
public final long getRightEdge()
Hitbox
getRightEdge
in class Hitbox<T extends CellGame>
public final long getTopEdge()
Hitbox
getTopEdge
in class Hitbox<T extends CellGame>
public final long getBottomEdge()
Hitbox
getBottomEdge
in class Hitbox<T extends CellGame>