Keybind enum

pull/12/head
Caroline Bell 2020-02-27 21:09:47 -08:00
parent 2f7ad5b2b6
commit 8b2ba123d9
2 changed files with 30 additions and 25 deletions

View File

@ -83,12 +83,12 @@ public class Litecraft extends Game
{
Input.addPressCallback(Keybind.EXIT, this::exit);
Input.addInitialPressCallback(Keybind.FULLSCREEN, Window::fullscreen);
Input.addPressCallback(Keybind.MOVE_FORWARDS, () -> this.movePlayer(RelativeDirection.FORWARD));
Input.addPressCallback(Keybind.MOVE_BACKWARDS, () -> this.movePlayer(RelativeDirection.BACKWARD));
Input.addPressCallback(Keybind.MOVE_LEFT, () -> this.movePlayer(RelativeDirection.LEFT));
Input.addPressCallback(Keybind.MOVE_RIGHT, () -> this.movePlayer(RelativeDirection.RIGHT));
Input.addPressCallback(Keybind.JUMP, () -> this.movePlayer(RelativeDirection.UP));
Input.addPressCallback(Keybind.SNEAK, () -> this.movePlayer(RelativeDirection.DOWN));
Input.addPressCallback(Keybind.MOVE_FORWARD, () -> this.movePlayer(RelativeDirection.FORWARD));
Input.addPressCallback(Keybind.MOVE_BACKWARD, () -> this.movePlayer(RelativeDirection.BACKWARD));
Input.addPressCallback(Keybind.STRAFE_LEFT, () -> this.movePlayer(RelativeDirection.LEFT));
Input.addPressCallback(Keybind.STRAFE_RIGHT, () -> this.movePlayer(RelativeDirection.RIGHT));
Input.addPressCallback(Keybind.FLY_UP, () -> this.movePlayer(RelativeDirection.UP));
Input.addPressCallback(Keybind.FLY_DOWN, () -> this.movePlayer(RelativeDirection.DOWN));
}
@Override

View File

@ -5,29 +5,34 @@ import org.lwjgl.glfw.GLFW;
/*
* Author: Valoeghese
*/
public final class Keybind
public enum Keybind
{
// movement
public static final Keybind MOVE_FORWARDS = new Keybind(GLFW.GLFW_KEY_W, false);
public static final Keybind MOVE_LEFT = new Keybind(GLFW.GLFW_KEY_A, false);
public static final Keybind MOVE_BACKWARDS = new Keybind(GLFW.GLFW_KEY_S, false);
public static final Keybind MOVE_RIGHT = new Keybind(GLFW.GLFW_KEY_D, false);
public static final Keybind JUMP = new Keybind(GLFW.GLFW_KEY_SPACE, false);
public static final Keybind SNEAK = new Keybind(GLFW.GLFW_KEY_LEFT_SHIFT, false);
// mouse
public static final Keybind USE = new Keybind(GLFW.GLFW_MOUSE_BUTTON_1, true);
// hotbar
public static final Keybind SELECT_0 = new Keybind(GLFW.GLFW_KEY_1, false);
public static final Keybind SELECT_1 = new Keybind(GLFW.GLFW_KEY_2, false);
public static final Keybind SELECT_2 = new Keybind(GLFW.GLFW_KEY_3, false);
// general
public static final Keybind EXIT = new Keybind(GLFW.GLFW_KEY_ESCAPE, false);
public static final Keybind FULLSCREEN = new Keybind(GLFW.GLFW_KEY_F11, false);
// ========================== //
MOVE_FORWARD(GLFW.GLFW_KEY_W, false), // Move the player forward relative to its facing direction
MOVE_BACKWARD(GLFW.GLFW_KEY_S, false), // Move the player backward relative to its facing direction
STRAFE_LEFT(GLFW.GLFW_KEY_A, false), // Move the player left relative to its facing direction
STRAFE_RIGHT(GLFW.GLFW_KEY_D, false), // Move the player right relative to its facing direction
FLY_UP(GLFW.GLFW_KEY_SPACE, false), // Move the player upward
FLY_DOWN(GLFW.GLFW_KEY_LEFT_SHIFT, false), // Move the player downward
BREAK(GLFW.GLFW_MOUSE_BUTTON_1, true), // Place a block in front of the player
PLACE(GLFW.GLFW_MOUSE_BUTTON_2, true), // Break the block in front of the player
SLOT_1(GLFW.GLFW_KEY_1, false), // Select the first item slot in the toolbar
SLOT_2(GLFW.GLFW_KEY_2, false), // Select the second item slot in the toolbar
SLOT_3(GLFW.GLFW_KEY_3, false), // Select the third item slot in the toolbar
SLOT_4(GLFW.GLFW_KEY_4, false), // Select the fourth item slot in the toolbar
SLOT_5(GLFW.GLFW_KEY_5, false), // Select the fifth item slot in the toolbar
SLOT_6(GLFW.GLFW_KEY_6, false), // Select the sixth item slot in the toolbar
SLOT_7(GLFW.GLFW_KEY_7, false), // Select the seventh item slot in the toolbar
SLOT_8(GLFW.GLFW_KEY_8, false), // Select the eighth item slot in the toolbar
SLOT_9(GLFW.GLFW_KEY_9, false), // Select the ninth item slot in the toolbar
SLOT_10(GLFW.GLFW_KEY_0, false), // Select the tenth item slot in the toolbar
EXIT(GLFW.GLFW_KEY_ESCAPE, false), // Save and exit the game // (Open the pause menu later)
DEBUG(GLFW.GLFW_KEY_F3, false), // Toggle debug text onscreen
FULLSCREEN(GLFW.GLFW_KEY_F11, false); // Toggle fullscreen mode
public int value;
public boolean mouse;
public Keybind(int initValue, boolean isMouse)
Keybind(int initValue, boolean isMouse)
{
this.value = initValue;
this.mouse = isMouse;