diff --git a/res/playerGreen.png b/res/playerGreen.png new file mode 100644 index 0000000..0c91240 Binary files /dev/null and b/res/playerGreen.png differ diff --git a/res/playerRed.png b/res/playerRed.png new file mode 100644 index 0000000..2e9ee09 Binary files /dev/null and b/res/playerRed.png differ diff --git a/src/game/Options.java b/src/game/Options.java index 416a83b..c74e0da 100644 --- a/src/game/Options.java +++ b/src/game/Options.java @@ -1,10 +1,27 @@ package game; +import game.graphics.Texture; + public class Options { public static boolean isWASD = true; + private static int chosenBallColor = 0; + + private static Texture[] ballColors = new Texture[] { + new Texture("res/playerBlue.png"), + new Texture("res/playerRed.png"), + new Texture("res/playerGreen.png"), + }; public Options() { } + + public static void setBallColor(int newBallColor) { + chosenBallColor = newBallColor; + } + + public static Texture getBallTexture() { + return ballColors[chosenBallColor]; + } } diff --git a/src/game/entity/Player.java b/src/game/entity/Player.java index 2d26113..a4eb802 100644 --- a/src/game/entity/Player.java +++ b/src/game/entity/Player.java @@ -41,8 +41,8 @@ public class Player { }; mesh = new VertexArray(vertices, indices, tcs); - // TODO: More color options? - texture = new Texture("res/playerBlue.png"); + + setColor(); if (Options.isWASD) { playerKeyUp = GLFW.GLFW_KEY_W; @@ -58,16 +58,32 @@ public class Player { } public void update() { - if (Input.keys[playerKeyUp]) + if (Input.keys[playerKeyUp]) { position.y += 0.1f; - if (Input.keys[playerKeyDown]) + } + if (Input.keys[playerKeyDown]) { position.y -= 0.1f; - if (Input.keys[playerKeyLeft]) + } + if (Input.keys[playerKeyLeft]) { position.x -= 0.1f; - if (Input.keys[playerKeyRight]) + } + if (Input.keys[playerKeyRight]) { position.x += 0.1f; + } // System.out.println("At (" + position.x + ", " + position.y + ")"); + + // Just for testing, change color by pressing corresponding number buttons + if (Input.keys[GLFW.GLFW_KEY_0]) { + Options.setBallColor(0); + setColor(); + } else if (Input.keys[GLFW.GLFW_KEY_1]) { + Options.setBallColor(1); + setColor(); + } else if (Input.keys[GLFW.GLFW_KEY_2]) { + Options.setBallColor(2); + setColor(); + } } public void render() { @@ -81,4 +97,8 @@ public class Player { public float getY() { return position.y; } + + private void setColor() { + texture = Options.getBallTexture(); + } }