Class KeyboardEntityController<T extends IMobileEntity>

java.lang.Object
de.gurkenlabs.litiengine.physics.MovementController<T>
de.gurkenlabs.litiengine.input.KeyboardEntityController<T>
Type Parameters:
T - the type of the mobile entity to be controlled
All Implemented Interfaces:
IEntityController, IUpdateable, IMovementController
Direct Known Subclasses:
PlatformingMovementController

public class KeyboardEntityController<T extends IMobileEntity> extends MovementController<T>
A controller that allows an entity to be controlled via keyboard input.
  • Constructor Details

    • KeyboardEntityController

      public KeyboardEntityController(T entity)
      Constructs a new KeyboardEntityController for the specified entity.
      Parameters:
      entity - the entity to be controlled by the keyboard
    • KeyboardEntityController

      public KeyboardEntityController(T entity, int up, int down, int left, int right)
      Constructs a new KeyboardEntityController for the specified entity.
      Parameters:
      entity - the entity to be controlled by the keyboard
      up - the key code for moving up
      down - the key code for moving down
      left - the key code for moving left
      right - the key code for moving right
  • Method Details

    • handlePressedKey

      public void handlePressedKey(KeyEvent keyCode)
      Handles the key pressed event and updates the entity's movement direction based on the key code.
      Parameters:
      keyCode - the key event containing the key code that was pressed
    • addUpKey

      public void addUpKey(int keyCode)
      Adds a key code to the list of keys for moving up.
      Parameters:
      keyCode - the key code to add for moving up
    • addDownKey

      public void addDownKey(int keyCode)
      Adds a key code to the list of keys for moving down.
      Parameters:
      keyCode - the key code to add for moving down
    • addLeftKey

      public void addLeftKey(int keyCode)
      Adds a key code to the list of keys for moving left.
      Parameters:
      keyCode - the key code to add for moving left
    • addRightKey

      public void addRightKey(int keyCode)
      Adds a key code to the list of keys for moving right.
      Parameters:
      keyCode - the key code to add for moving right
    • getUpKeys

      public List<Integer> getUpKeys()
      Gets the list of key codes for moving up.
      Returns:
      the list of key codes for moving up
    • getDownKeys

      public List<Integer> getDownKeys()
      Gets the list of key codes for moving down.
      Returns:
      the list of key codes for moving down
    • getLeftKeys

      public List<Integer> getLeftKeys()
      Gets the list of key codes for moving left.
      Returns:
      the list of key codes for moving left
    • getRightKeys

      public List<Integer> getRightKeys()
      Gets the list of key codes for moving right.
      Returns:
      the list of key codes for moving right
    • setUpKeys

      public void setUpKeys(int... up)
      Sets the key codes for moving up.
      Parameters:
      up - the key codes for moving up
    • setUpKeys

      public void setUpKeys(List<Integer> up)
      Sets the key codes for moving up.
      Parameters:
      up - the list of key codes for moving up
    • setDownKeys

      public void setDownKeys(int... down)
      Sets the key codes for moving down.
      Parameters:
      down - the key codes for moving down
    • setDownKeys

      public void setDownKeys(List<Integer> down)
      Sets the key codes for moving down.
      Parameters:
      down - the list of key codes for moving down
    • setLeftKeys

      public void setLeftKeys(int... left)
      Sets the key codes for moving left.
      Parameters:
      left - the key codes for moving left
    • setLeftKeys

      public void setLeftKeys(List<Integer> left)
      Sets the key codes for moving left.
      Parameters:
      left - the list of key codes for moving left
    • setRightKeys

      public void setRightKeys(int... right)
      Sets the key codes for moving right.
      Parameters:
      right - the key codes for moving right
    • setRightKeys

      public void setRightKeys(List<Integer> right)
      Sets the key codes for moving right.
      Parameters:
      right - the list of key codes for moving right