From 951fe9ddb0bf860e448130e671b7c3d42c92f828 Mon Sep 17 00:00:00 2001 From: Billy Gallagher Date: Fri, 15 Apr 2016 15:03:32 -0400 Subject: [PATCH] Added basic option controls, can switch between WASD and arrow keys. Need way to interact with it in-game. --- src/game/Options.java | 10 ++++++++++ src/game/entity/Player.java | 26 ++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/game/Options.java diff --git a/src/game/Options.java b/src/game/Options.java new file mode 100644 index 0000000..416a83b --- /dev/null +++ b/src/game/Options.java @@ -0,0 +1,10 @@ +package game; + +public class Options { + + public static boolean isWASD = true; + + public Options() { + + } +} diff --git a/src/game/entity/Player.java b/src/game/entity/Player.java index e70becd..2d26113 100644 --- a/src/game/entity/Player.java +++ b/src/game/entity/Player.java @@ -1,8 +1,8 @@ package game.entity; -import static org.lwjgl.glfw.GLFW.*; import org.lwjgl.glfw.GLFW; +import game.Options; import game.graphics.Shader; import game.graphics.Texture; import game.graphics.VertexArray; @@ -18,6 +18,8 @@ public class Player { private Vector3f position = new Vector3f(); + private int playerKeyUp, playerKeyDown, playerKeyLeft, playerKeyRight; + public Player() { float[] vertices = new float[] { -SIZE / 2.0f, -SIZE / 2.0f, 0.2f, @@ -41,19 +43,31 @@ public class Player { mesh = new VertexArray(vertices, indices, tcs); // TODO: More color options? texture = new Texture("res/playerBlue.png"); + + if (Options.isWASD) { + playerKeyUp = GLFW.GLFW_KEY_W; + playerKeyDown = GLFW.GLFW_KEY_S; + playerKeyLeft = GLFW.GLFW_KEY_A; + playerKeyRight = GLFW.GLFW_KEY_D; + } else { + playerKeyUp = GLFW.GLFW_KEY_UP; + playerKeyDown = GLFW.GLFW_KEY_DOWN; + playerKeyLeft = GLFW.GLFW_KEY_LEFT; + playerKeyRight = GLFW.GLFW_KEY_RIGHT; + } } public void update() { - if (Input.keys[GLFW.GLFW_KEY_UP]) + if (Input.keys[playerKeyUp]) position.y += 0.1f; - if (Input.keys[GLFW.GLFW_KEY_DOWN]) + if (Input.keys[playerKeyDown]) position.y -= 0.1f; - if (Input.keys[GLFW.GLFW_KEY_LEFT]) + if (Input.keys[playerKeyLeft]) position.x -= 0.1f; - if (Input.keys[GLFW.GLFW_KEY_RIGHT]) + if (Input.keys[playerKeyRight]) position.x += 0.1f; - System.out.println("At (" + position.x + ", " + position.y + ")"); +// System.out.println("At (" + position.x + ", " + position.y + ")"); } public void render() {