Skip to content
Permalink
951fe9ddb0
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
84 lines (69 sloc) 1.82 KB
package game.entity;
import org.lwjgl.glfw.GLFW;
import game.Options;
import game.graphics.Shader;
import game.graphics.Texture;
import game.graphics.VertexArray;
import game.input.Input;
import game.math.Matrix4f;
import game.math.Vector3f;
public class Player {
private float SIZE = 1.0f;
private VertexArray mesh;
private Texture texture;
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,
-SIZE / 2.0f, SIZE / 2.0f, 0.2f,
SIZE / 2.0f, SIZE / 2.0f, 0.2f,
SIZE / 2.0f, -SIZE / 2.0f, 0.2f,
};
byte[] indices = new byte[] {
0, 1, 2,
2, 3, 0
};
float[] tcs = new float[] {
0, 1,
0, 0,
1, 0,
1, 1
};
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[playerKeyUp])
position.y += 0.1f;
if (Input.keys[playerKeyDown])
position.y -= 0.1f;
if (Input.keys[playerKeyLeft])
position.x -= 0.1f;
if (Input.keys[playerKeyRight])
position.x += 0.1f;
// System.out.println("At (" + position.x + ", " + position.y + ")");
}
public void render() {
Shader.PLAYER.enable();
Shader.PLAYER.setUniformMat4f("ml_matrix", Matrix4f.translate(position));
texture.bind();
mesh.render();
Shader.PLAYER.disable();
}
public float getY() {
return position.y;
}
}