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
FieldsFields inherited from class de.tum.cit.ase.maze.objects.dynamic.Character
deathListener, frameHeight, frameWidth, health, speed, state, stateTime, walkDirectionList, walkTypesAnimationMap, ZOOMFields inherited from class de.tum.cit.ase.maze.objects.GameElement
body, texture, world -
Constructor Summary
ConstructorsConstructorDescriptionPlayer(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 TypeMethodDescriptionbooleanaddCollectable(TimedCollectable collectable) Adds aTimedCollectableto the player's collection and plays a sound effect.voidattack(int damage) Method to attack enemiesvoidcollectKey(Key key) Adds a key to the player's key list and plays a sound effect.voiddispose()Releases all resources of this object.booleanbooleanbooleanisSprint()booleanvoidmakeDamage(int damage) Applies damage.voidvoidrender(com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch) Renders the appearance of the PlayervoidsetAttacking(boolean attacking) voidsetInReach(boolean inReach) voidsetSprint(boolean sprint) Requests elevated SpeedvoidsetVulnerable(boolean vulnerable) voidstartMoving(WalkDirection direction) Starts moving in defined direction.voidstopMoving(WalkDirection direction) Stops moving for one direction.voidupdate(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 aTimedCollectableto the player's collection and plays a sound effect.- Parameters:
collectable- TheTimedCollectableto be added.- Returns:
- True if the
TimedCollectablewas successfully added, false otherwise.
-
update
public void update(float deltaTime) Description copied from class:CharacterMoves the Object -
makeDamage
public void makeDamage(int damage) Description copied from class:CharacterApplies damage.- Overrides:
makeDamagein 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:
startMovingin 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:
stopMovingin 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:
disposein interfacecom.badlogic.gdx.utils.Disposable
-
render
public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch) Renders the appearance of the Player- Specified by:
renderin 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)
-