public class Interactable
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
(package private) int |
height
The height of the object
|
private java.awt.Rectangle |
relativeCollisionBox
The collision box used by the object.
|
(package private) int |
width
The width of the object
|
(package private) int |
xLocation
The x-location of the object
|
(package private) int |
yLocation
The y-location of the object
|
Constructor and Description |
---|
Interactable(int x,
int y,
int width,
int height)
Create a new Interactable with the given position and dimensions.
|
Modifier and Type | Method and Description |
---|---|
void |
addXLocation(int dx)
Adds to the x-coordinate of the Interactable.
|
void |
addYLocation(int dy)
Adds to the y-coordinate of the Interactable.
|
boolean |
getCollidesWith(Interactable other)
Determines whether this Interactable and another are colliding according to their collision boxes.
|
java.awt.Rectangle |
getCollisionRect()
Returns a rectangle representing the collision box of the Interactable, relative to world coordinate 0,0.
Note that this is different from the
relativeCollisionBox used internally. |
int |
getHeight()
Gets the
height of the Interactable |
int |
getWidth()
Gets the
width of the Interactable |
int |
getXLocation()
Gets the current x-location of the Interactable.
|
int |
getYLocation()
Gets the current y-location of the Interactable.
|
protected void |
setRelativeCollisionRect(int dx,
int dy,
int width,
int height)
Sets the relative collision box of this interactable.
|
void |
setXLocation(int x)
Sets the x-coordinate of the Interactable
|
void |
setYLocation(int y)
Sets the y-coordinate of the Interactable
|
int xLocation
int yLocation
int width
int height
private java.awt.Rectangle relativeCollisionBox
public Interactable(int x, int y, int width, int height)
x
- The x-location of the objecty
- The y-location of the objectwidth
- The width of the objectheight
- The height of the objectpublic java.awt.Rectangle getCollisionRect()
relativeCollisionBox
used internally.protected void setRelativeCollisionRect(int dx, int dy, int width, int height)
dx
- The x-coordinate of the left side of the box, relative to the Interactable's x-position.dy
- The y-coordinate of the top side of the box, relative to the Interactable's y-position.width
- The width of the boxheight
- The height of the boxpublic boolean getCollidesWith(Interactable other)
public int getHeight()
height
of the Interactableheight
of the Interactablepublic int getWidth()
width
of the Interactablewidth
of the Interactablepublic void setXLocation(int x)
x
- The new x-coordinatepublic void setYLocation(int y)
y
- The new y-coordinatepublic void addXLocation(int dx)
can
is at x=200
and someone calls can.addXLocation(50)
,
then the can will now be located at x=250
.dx
- The amount to add to the x-coordinatepublic void addYLocation(int dy)
can
is at y=200
and someone calls can.addYLocation(50)
,
then the can will now be located at y=250
.dy
- The amount to add to the y-coordinatepublic int getXLocation()
public int getYLocation()