Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added basic option controls, can switch between WASD and arrow keys. …
…Need way to interact with it in-game.
  • Loading branch information
wjg12004 committed Apr 15, 2016
1 parent 78e8b4c commit 951fe9d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/game/Options.java
@@ -0,0 +1,10 @@
package game;

public class Options {

public static boolean isWASD = true;

public Options() {

}
}
26 changes: 20 additions & 6 deletions 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;
Expand All @@ -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,
Expand All @@ -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() {
Expand Down

0 comments on commit 951fe9d

Please sign in to comment.