public class Player extends Interactable implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
private Direction |
direction
Movement direction.
|
private int |
dx
Horizontal movement direction.
|
private int |
dy
Vertical movement direction.
|
private int |
health
Player's health
|
private int |
SPEED
Movement speed
|
private PlayerStatus |
status
Player status, i.e. IDLE or WALKING, etc.
|
Constructor and Description |
---|
Player(int xLoc,
int yLoc,
int rWidth,
int rHeight)
Create a player with the given position and size, and sets up the collision box.
|
Modifier and Type | Method and Description |
---|---|
void |
alterVelocity(int ddx,
int ddy)
|
Direction |
getDirection()
Gets the current
direction of the Player |
int |
getDx()
Returns the Dx of the current Player.
|
int |
getDy()
Returns the Dy of the current Player
|
int |
getHealth()
Gets the current health of the player
|
int |
getSpeed() |
PlayerStatus |
getStatus()
Gets the current
status of the player |
void |
loseHealth()
Decrement the player's health by 10
|
void |
move()
Moves the player according to it's speed and velocity.
|
void |
setDirection(Direction d)
Change the player's direction to the parameter
|
void |
setSpeed(int speed) |
void |
stop() |
addXLocation, addYLocation, getCollidesWith, getCollisionRect, getHeight, getWidth, getXLocation, getYLocation, setRelativeCollisionRect, setXLocation, setYLocation
private int dx
-1
for moving left,
0
for horizontally stable (initial value),
1
for moving right.private int dy
-1
for moving up,
0
for vertically stable (initial value),
1
for moving down.private int SPEED
private Direction direction
private PlayerStatus status
private int health
public Player(int xLoc, int yLoc, int rWidth, int rHeight)
xLoc
- The x-location of the PlayeryLoc
- The y-location of the PlayerrWidth
- The width of the PlayerrHeight
- The height of the Playerpublic int getDx()
public int getDy()
public void alterVelocity(int ddx, int ddy)
public void move()
public Direction getDirection()
direction
of the Playerdirection
of the Playerpublic PlayerStatus getStatus()
status
of the playerstatus
of the Playerpublic void setDirection(Direction d)
d
- The new directionpublic int getHealth()
public void loseHealth()
empty
- public void setSpeed(int speed)
public void stop()
public int getSpeed()