Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ability to change ball color is there, along with a few basic colors.
  • Loading branch information
wjg12004 committed Apr 15, 2016
1 parent 28ddad3 commit d89f901
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Binary file added res/playerGreen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/playerRed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions 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];
}
}
32 changes: 26 additions & 6 deletions src/game/entity/Player.java
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -81,4 +97,8 @@ public class Player {
public float getY() {
return position.y;
}

private void setColor() {
texture = Options.getBallTexture();
}
}

0 comments on commit d89f901

Please sign in to comment.