Class Player

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Movable

public class Player extends Character implements Movable
Class represents the Player. The player is the main character that can be controlled by a person.
  • 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-Coordinate
      y - 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

      public boolean addCollectable(TimedCollectable collectable)
      Adds a TimedCollectable to the player's collection and plays a sound effect.
      Parameters:
      collectable - The TimedCollectable 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
      Overrides:
      update in class Character
      Parameters:
      deltaTime - Time since last frame.
    • makeDamage

      public void makeDamage(int damage)
      Description copied from class: Character
      Applies damage.
      Overrides:
      makeDamage in class Character
      Parameters:
      damage - damage to apply
    • attack

      public void attack(int damage)
      Method to attack enemies
    • startMoving

      public void startMoving(WalkDirection direction)
      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 interface Movable
      Parameters:
      direction - Direction to move.
    • stopMoving

      public void stopMoving(WalkDirection direction)
      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 interface Movable
      Parameters:
      direction - Direction to stop moving.
    • collectKey

      public void collectKey(Key key)
      Adds a key to the player's key list and plays a sound effect.
      Parameters:
      key - The key to be added.
    • getTimedCollectables

      public Set<TimedCollectable> getTimedCollectables()
    • markAsFinished

      public void markAsFinished()
    • dispose

      public void dispose()
      Releases all resources of this object.
      Specified by:
      dispose in interface com.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 class GameElement
      Parameters:
      spriteBatch -
    • isVulnerable

      public boolean isVulnerable()
    • setVulnerable

      public void setVulnerable(boolean vulnerable)
    • getKeyList

      public List<Key> 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)