Class Player
java.lang.Object
de.tum.cit.ase.maze.objects.GameElement
de.tum.cit.ase.maze.objects.dynamic.Character
de.tum.cit.ase.maze.objects.dynamic.Player
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Movable
Class represents the Player. The player is the main character that can be controlled by a person.
-
Field Summary
Fields inherited from class de.tum.cit.ase.maze.objects.dynamic.Character
deathListener, frameHeight, frameWidth, health, speed, state, stateTime, walkDirectionList, walkTypesAnimationMap, ZOOM
Fields inherited from class de.tum.cit.ase.maze.objects.GameElement
body, texture, world
-
Constructor Summary
ConstructorDescriptionPlayer
(com.badlogic.gdx.physics.box2d.World world, DeathListener deathListener, box2dLight.RayHandler rayHandler) Player
(com.badlogic.gdx.physics.box2d.World world, DeathListener deathListener, box2dLight.RayHandler rayHandler, float x, float y) Creates a Player with respective coordinates.Player
(com.badlogic.gdx.physics.box2d.World world, DeathListener deathListener, box2dLight.RayHandler rayHandler, com.badlogic.gdx.math.Vector2 position) Constructs a Player object with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addCollectable
(TimedCollectable collectable) Adds aTimedCollectable
to the player's collection and plays a sound effect.void
attack
(int damage) Method to attack enemiesvoid
collectKey
(Key key) Adds a key to the player's key list and plays a sound effect.void
dispose()
Releases all resources of this object.boolean
boolean
boolean
isSprint()
boolean
void
makeDamage
(int damage) Applies damage.void
void
render
(com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch) Renders the appearance of the Playervoid
setAttacking
(boolean attacking) void
setInReach
(boolean inReach) void
setSprint
(boolean sprint) Requests elevated Speedvoid
setVulnerable
(boolean vulnerable) void
startMoving
(WalkDirection direction) Starts moving in defined direction.void
stopMoving
(WalkDirection direction) Stops moving for one direction.void
update
(float deltaTime) Moves the ObjectMethods inherited from class de.tum.cit.ase.maze.objects.dynamic.Character
getBody, getDimensions, getHealth, getPosition, getSpeed, getTexture, heal, isDead, setSpeed
-
Field Details
-
SPRINT_BOOST
public final float SPRINT_BOOST- See Also:
-
numberOfKeys
public final int numberOfKeys
-
-
Constructor Details
-
Player
public Player(com.badlogic.gdx.physics.box2d.World world, DeathListener deathListener, box2dLight.RayHandler rayHandler) -
Player
public Player(com.badlogic.gdx.physics.box2d.World world, DeathListener deathListener, box2dLight.RayHandler rayHandler, float x, float y) Creates a Player with respective coordinates.- Parameters:
x
- X-Coordinatey
- Y-Coordinate
-
Player
public Player(com.badlogic.gdx.physics.box2d.World world, DeathListener deathListener, box2dLight.RayHandler rayHandler, com.badlogic.gdx.math.Vector2 position) Constructs a Player object with the given parameters.- Parameters:
world
- The world the player belongs to.deathListener
- The listener for player death events.rayHandler
- The ray handler for handling light and shadows.position
- The initial position of the player.
-
-
Method Details
-
addCollectable
Adds aTimedCollectable
to the player's collection and plays a sound effect.- Parameters:
collectable
- TheTimedCollectable
to be added.- Returns:
- True if the
TimedCollectable
was successfully added, false otherwise.
-
update
public void update(float deltaTime) Description copied from class:Character
Moves the Object -
makeDamage
public void makeDamage(int damage) Description copied from class:Character
Applies damage.- Overrides:
makeDamage
in classCharacter
- Parameters:
damage
- damage to apply
-
attack
public void attack(int damage) Method to attack enemies -
startMoving
Starts moving in defined direction. Should NOT move in two directions. e.g. left and up. But after release other pressed buttons take over.- Specified by:
startMoving
in interfaceMovable
- Parameters:
direction
- Direction to move.
-
stopMoving
Stops moving for one direction. For example if Object moves left, but was overridden, it does not stop if it should stop moving right. And also allows after stopping to move into other requested directions.- Specified by:
stopMoving
in interfaceMovable
- Parameters:
direction
- Direction to stop moving.
-
collectKey
Adds a key to the player's key list and plays a sound effect.- Parameters:
key
- The key to be added.
-
getTimedCollectables
-
markAsFinished
public void markAsFinished() -
dispose
public void dispose()Releases all resources of this object.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-
render
public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch) Renders the appearance of the Player- Specified by:
render
in classGameElement
- Parameters:
spriteBatch
-
-
isVulnerable
public boolean isVulnerable() -
setVulnerable
public void setVulnerable(boolean vulnerable) -
getKeyList
-
isSprint
public boolean isSprint() -
setSprint
public void setSprint(boolean sprint) Requests elevated Speed- Parameters:
sprint
-
-
isAttacking
public boolean isAttacking() -
setAttacking
public void setAttacking(boolean attacking) -
isInReach
public boolean isInReach() -
setInReach
public void setInReach(boolean inReach)
-