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
A controller that allows an entity to be controlled via keyboard input.
-
Constructor Summary
ConstructorsConstructorDescriptionKeyboardEntityController(T entity) Constructs a new KeyboardEntityController for the specified entity.KeyboardEntityController(T entity, int up, int down, int left, int right) Constructs a new KeyboardEntityController for the specified entity. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDownKey(int keyCode) Adds a key code to the list of keys for moving down.voidaddLeftKey(int keyCode) Adds a key code to the list of keys for moving left.voidaddRightKey(int keyCode) Adds a key code to the list of keys for moving right.voidaddUpKey(int keyCode) Adds a key code to the list of keys for moving up.Gets the list of key codes for moving down.Gets the list of key codes for moving left.Gets the list of key codes for moving right.Gets the list of key codes for moving up.voidhandlePressedKey(KeyEvent keyCode) Handles the key pressed event and updates the entity's movement direction based on the key code.voidsetDownKeys(int... down) Sets the key codes for moving down.voidsetDownKeys(List<Integer> down) Sets the key codes for moving down.voidsetLeftKeys(int... left) Sets the key codes for moving left.voidsetLeftKeys(List<Integer> left) Sets the key codes for moving left.voidsetRightKeys(int... right) Sets the key codes for moving right.voidsetRightKeys(List<Integer> right) Sets the key codes for moving right.voidsetUpKeys(int... up) Sets the key codes for moving up.voidSets the key codes for moving up.Methods inherited from class de.gurkenlabs.litiengine.physics.MovementController
apply, attach, detach, getActiveForces, getDx, getDy, getEntity, getForce, getMoveAngle, getVelocity, handleMovement, isMovementAllowed, moveEntity, onMovementCheck, setDx, setDy, setVelocity, update
-
Constructor Details
-
KeyboardEntityController
Constructs a new KeyboardEntityController for the specified entity.- Parameters:
entity- the entity to be controlled by the keyboard
-
KeyboardEntityController
Constructs a new KeyboardEntityController for the specified entity.- Parameters:
entity- the entity to be controlled by the keyboardup- the key code for moving updown- the key code for moving downleft- the key code for moving leftright- the key code for moving right
-
-
Method Details
-
handlePressedKey
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
-
getDownKeys
-
getLeftKeys
-
getRightKeys
-
setUpKeys
public void setUpKeys(int... up) Sets the key codes for moving up.- Parameters:
up- the key codes for moving up
-
setUpKeys
-
setDownKeys
public void setDownKeys(int... down) Sets the key codes for moving down.- Parameters:
down- the key codes for moving down
-
setDownKeys
-
setLeftKeys
public void setLeftKeys(int... left) Sets the key codes for moving left.- Parameters:
left- the key codes for moving left
-
setLeftKeys
-
setRightKeys
public void setRightKeys(int... right) Sets the key codes for moving right.- Parameters:
right- the key codes for moving right
-
setRightKeys
-