Class WorkerInputComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.input.InputComponent
com.deco2800.game.worker.components.movement.WorkerInputComponent
- All Implemented Interfaces:
com.badlogic.gdx.input.GestureDetector.GestureListener
,com.badlogic.gdx.InputProcessor
Input handler for selecting, un-selecting and moving worker units
-
Field Summary
Fields inherited from class com.deco2800.game.input.InputComponent
priority
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.com.badlogic.gdx.math.Rectangle
Return a Rectangle which represents the region in the game occupied by the entity.boolean
inEntityBounds
(float x, float y) Determines if a given point (x,y) is within the entity's boundsboolean
Return whether the entity is selected or notboolean
keyDown
(int keyCode) Deselects worker when ESC key is pressed.com.badlogic.gdx.math.Vector2
screenToWorldPosition
(int screenX, int screenY) Converts from screen coordinates to world coordinates, and returns them as a Vector2.boolean
touchDown
(int screenX, int screenY, int pointer, int button) Determines whether to select unit on left-mouse click Moves a selected unit on right-mouse clickMethods inherited from class com.deco2800.game.input.InputComponent
dispose, fling, getPriority, keyTyped, keyUp, longPress, mouseMoved, pan, panStop, pinch, pinchStop, pinchStopHandled, scrolled, setPriority, tap, touchDown, touchDragged, touchUp, zoom
Methods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, isAnimationRenderComponent, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
WorkerInputComponent
public WorkerInputComponent()
-
-
Method Details
-
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.- Overrides:
create
in classInputComponent
-
touchDown
public boolean touchDown(int screenX, int screenY, int pointer, int button) Determines whether to select unit on left-mouse click Moves a selected unit on right-mouse click- Specified by:
touchDown
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDown
in classInputComponent
- Parameters:
screenX
- The x coordinate, origin is in the upper left cornerscreenY
- The y coordinate, origin is in the upper left cornerpointer
- the pointer for the eventbutton
- the button- Returns:
- whether the input was processed
- See Also:
-
InputProcessor.touchDown(int, int, int, int)
-
keyDown
public boolean keyDown(int keyCode) Deselects worker when ESC key is pressed.- Specified by:
keyDown
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
keyDown
in classInputComponent
- Parameters:
keyCode
- the key typed- Returns:
- whether the input was processed
- See Also:
-
InputProcessor.keyDown(int)
-
isSelected
public boolean isSelected()Return whether the entity is selected or not- Returns:
- True if the entity is selected. False otherwise.
-
screenToWorldPosition
public com.badlogic.gdx.math.Vector2 screenToWorldPosition(int screenX, int screenY) Converts from screen coordinates to world coordinates, and returns them as a Vector2.- Parameters:
screenX
- the x coordinate on the screenscreenY
- the y coordinate on the screen- Returns:
- the equivalent world coordinates
-
getEntityBounds
public com.badlogic.gdx.math.Rectangle getEntityBounds()Return a Rectangle which represents the region in the game occupied by the entity.- Returns:
- the rectangle representing the entity's region in the game
-
inEntityBounds
public boolean inEntityBounds(float x, float y) Determines if a given point (x,y) is within the entity's bounds- Parameters:
x
- the x coordinate of the point's world positiony
- the y coordinate of the point's world position- Returns:
- true if the point is in the entity's bounds. False otherwise.
-