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 TypeMethodDescriptionvoidcreate()Called when the entity is created and registered.com.badlogic.gdx.math.RectangleReturn a Rectangle which represents the region in the game occupied by the entity.booleaninEntityBounds(float x, float y) Determines if a given point (x,y) is within the entity's boundsbooleanReturn whether the entity is selected or notbooleankeyDown(int keyCode) Deselects worker when ESC key is pressed.com.badlogic.gdx.math.Vector2screenToWorldPosition(int screenX, int screenY) Converts from screen coordinates to world coordinates, and returns them as a Vector2.booleantouchDown(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, zoomMethods 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:ComponentCalled 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:
createin 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:
touchDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDownin 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:
keyDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
keyDownin 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.
-