Package tech.underoaks.coldcase.game
Class PlayerController
java.lang.Object
tech.underoaks.coldcase.game.PlayerController
- All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
Handles player input and movement
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddestroy()Destroys the singleton instance ofPlayerControllerby setting it tonull.static PlayerControllerReturns the singleton instance ofPlayerController.Returns the player's inventory.Returns the current direction the player is looking towards.com.badlogic.gdx.math.Vector2Retrieves the current position of the player.booleankeyDown(int keycode) booleankeyTyped(char character) booleankeyUp(int keycode) Called when a key was releasedbooleanmouseMoved(int screenX, int screenY) voidResets the player's movement state, stopping any auto-move and resetting the key hold time.booleanscrolled(float amountX, float amountY) voidsetInventory(TileContent inventory) Sets the player's inventory.voidsetPlayerDirection(Direction lookDirection) Sets the direction the player is looking towards.voidsetPlayerPosition(com.badlogic.gdx.math.Vector2 playerPosition) Sets the player's current position.booleantouchCancelled(int screenX, int screenY, int pointer, int button) booleantouchDown(int screenX, int screenY, int pointer, int button) booleantouchDragged(int screenX, int screenY, int pointer) booleantouchUp(int screenX, int screenY, int pointer, int button) voidupdate()Updates the player's movement.
-
Constructor Details
-
PlayerController
public PlayerController()
-
-
Method Details
-
getInventory
Returns the player's inventory.- Returns:
- the
TileContentrepresenting the player's inventory, ornullif not set
-
setInventory
Sets the player's inventory. Additionally, prints the inventory to the console for debugging purposes if the inventory is notnull.- Parameters:
inventory- theTileContentrepresenting the new inventory
-
getInstance
Returns the singleton instance ofPlayerController. If the instance does not exist yet, it is created.- Returns:
- the singleton
PlayerControllerinstance
-
destroy
public static void destroy()Destroys the singleton instance ofPlayerControllerby setting it tonull. 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- aVector2representing 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
Vector2representing the player's position on the map
-
setPlayerDirection
Sets the direction the player is looking towards.- Parameters:
lookDirection- the newDirectionfor the player
-
getPlayerDirection
Returns the current direction the player is looking towards.- Returns:
- the
Directionthe player is currently facing
-
keyDown
public boolean keyDown(int keycode) - Specified by:
keyDownin interfacecom.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:
keyUpin interfacecom.badlogic.gdx.InputProcessor- Parameters:
keycode- one of the constants inInput.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:
keyTypedin interfacecom.badlogic.gdx.InputProcessor
-
touchDown
public boolean touchDown(int screenX, int screenY, int pointer, int button) - Specified by:
touchDownin interfacecom.badlogic.gdx.InputProcessor
-
touchUp
public boolean touchUp(int screenX, int screenY, int pointer, int button) - Specified by:
touchUpin interfacecom.badlogic.gdx.InputProcessor
-
touchCancelled
public boolean touchCancelled(int screenX, int screenY, int pointer, int button) - Specified by:
touchCancelledin interfacecom.badlogic.gdx.InputProcessor
-
touchDragged
public boolean touchDragged(int screenX, int screenY, int pointer) - Specified by:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor
-
mouseMoved
public boolean mouseMoved(int screenX, int screenY) - Specified by:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor
-
scrolled
public boolean scrolled(float amountX, float amountY) - Specified by:
scrolledin interfacecom.badlogic.gdx.InputProcessor
-