Class PlayerController

java.lang.Object
tech.underoaks.coldcase.game.PlayerController
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor

public class PlayerController extends Object implements com.badlogic.gdx.InputProcessor
Handles player input and movement
  • Constructor Details

    • PlayerController

      public PlayerController()
  • Method Details

    • getInventory

      public TileContent getInventory()
      Returns the player's inventory.
      Returns:
      the TileContent representing the player's inventory, or null if not set
    • setInventory

      public void setInventory(TileContent inventory)
      Sets the player's inventory. Additionally, prints the inventory to the console for debugging purposes if the inventory is not null.
      Parameters:
      inventory - the TileContent representing the new inventory
    • getInstance

      public static PlayerController getInstance()
      Returns the singleton instance of PlayerController. If the instance does not exist yet, it is created.
      Returns:
      the singleton PlayerController instance
    • destroy

      public static void destroy()
      Destroys the singleton instance of PlayerController by setting it to null. This is typically used to reset the controller for a new game session.
    • setPlayerPosition

      public void setPlayerPosition(com.badlogic.gdx.math.Vector2 playerPosition)
      Sets the player's current position.
      Parameters:
      playerPosition - a Vector2 representing the new position of the player on the map
    • getPlayerPosition

      public com.badlogic.gdx.math.Vector2 getPlayerPosition()
      Retrieves the current position of the player.
      Returns:
      a Vector2 representing the player's position on the map
    • setPlayerDirection

      public void setPlayerDirection(Direction lookDirection)
      Sets the direction the player is looking towards.
      Parameters:
      lookDirection - the new Direction for the player
    • getPlayerDirection

      public Direction getPlayerDirection()
      Returns the current direction the player is looking towards.
      Returns:
      the Direction the player is currently facing
    • keyDown

      public boolean keyDown(int keycode)
      Specified by:
      keyDown in interface com.badlogic.gdx.InputProcessor
    • update

      public void update()
      Updates the player's movement.

      If the player is moving, this method increments the key hold time based on the frame's delta time and triggers an auto-move action if the hold time exceeds the defined auto-move threshold.

    • keyUp

      public boolean keyUp(int keycode)
      Called when a key was released
      Specified by:
      keyUp in interface com.badlogic.gdx.InputProcessor
      Parameters:
      keycode - one of the constants in Input.Keys
      Returns:
      whether the input was processed
    • resetMovement

      public void resetMovement()
      Resets the player's movement state, stopping any auto-move and resetting the key hold time.
    • keyTyped

      public boolean keyTyped(char character)
      Specified by:
      keyTyped in interface com.badlogic.gdx.InputProcessor
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
    • touchUp

      public boolean touchUp(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
    • touchCancelled

      public boolean touchCancelled(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchCancelled in interface com.badlogic.gdx.InputProcessor
    • touchDragged

      public boolean touchDragged(int screenX, int screenY, int pointer)
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
    • mouseMoved

      public boolean mouseMoved(int screenX, int screenY)
      Specified by:
      mouseMoved in interface com.badlogic.gdx.InputProcessor
    • scrolled

      public boolean scrolled(float amountX, float amountY)
      Specified by:
      scrolled in interface com.badlogic.gdx.InputProcessor