Class KeyboardPlayerInputComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.input.InputComponent
com.csse3200.game.components.player.KeyboardPlayerInputComponent
All Implemented Interfaces:
com.badlogic.gdx.input.GestureDetector.GestureListener, com.badlogic.gdx.InputProcessor

public class KeyboardPlayerInputComponent extends InputComponent
Input handler for the player for keyboard and touch (mouse) input. This input handler only uses keyboard input.
  • Constructor Details

    • KeyboardPlayerInputComponent

      public KeyboardPlayerInputComponent()
  • Method Details

    • keyPressed

      public boolean keyPressed(int keycode)
      Triggers player events on specific keycodes.
      Specified by:
      keyPressed in class InputComponent
      Parameters:
      keycode - The key code of the key that was pressed.
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.keyDown(int)
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Handles mouse button presses. If the player clicks the left mouse button, this triggers a ranged or melee attack depending on the currently equipped item.
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDown in class InputComponent
      Parameters:
      screenX - the x-coordinate of the touch in screen space
      screenY - the y-coordinate of the touch in screen space
      pointer - the pointer index for the event
      button - the mouse button pressed
      Returns:
      true if the input was handled, false otherwise
      See Also:
      • InputProcessor.touchDown(int, int, int, int)
    • keyReleased

      public boolean keyReleased(int keycode)
      Triggers player events on specific keycodes.
      Specified by:
      keyReleased in class InputComponent
      Parameters:
      keycode - The key code of the key that was pressed.
      Returns:
      whether the input was processed
      See Also:
      • InputProcessor.keyUp(int)
    • checkSlot

      public void checkSlot(int slot)
      Checks if the player is holding an item to be equipped if an item is equipped then unequip's item in given slot, if an item is not currently equipped then equips item in given slot.
      Parameters:
      slot - The slot to check
    • equipCurrentItem

      public void equipCurrentItem()
      equips the player with the weapon that is in the selected slot
    • unequipCurrentItem

      public void unequipCurrentItem()
      this function is to unequip the player