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

public class WorkerInputComponent extends InputComponent
Input handler for selecting, un-selecting and moving worker units
  • 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 class InputComponent
    • 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 interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDown in class InputComponent
      Parameters:
      screenX - The x coordinate, origin is in the upper left corner
      screenY - The y coordinate, origin is in the upper left corner
      pointer - the pointer for the event
      button - 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 interface com.badlogic.gdx.InputProcessor
      Overrides:
      keyDown in class InputComponent
      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 screen
      screenY - 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 position
      y - the y coordinate of the point's world position
      Returns:
      true if the point is in the entity's bounds. False otherwise.