Permalink
Cannot retrieve contributors at this time
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?
GameNoodle/src/game/level/tiles/Tile.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
73 lines (59 sloc)
1.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package game.level.tiles; | |
import game.graphics.Shader; | |
import game.graphics.Texture; | |
import game.graphics.VertexArray; | |
import game.math.Matrix4f; | |
import game.math.Vector3f; | |
public abstract class Tile { | |
protected Vector3f position = new Vector3f(); | |
protected boolean isWall; | |
protected static final float SIZE = 1.0f; | |
protected Texture texture; | |
protected Matrix4f ml_matrix; | |
protected static VertexArray mesh; | |
private static float[] vertices; | |
private static float[] tcs; | |
private static byte[] indices; | |
public static void create() { | |
vertices = new float[] { | |
-SIZE / 2.0f, -SIZE / 2.0f, 0.1f, | |
-SIZE / 2.0f, SIZE / 2.0f, 0.1f, | |
SIZE / 2.0f, SIZE / 2.0f, 0.1f, | |
SIZE / 2.0f, -SIZE / 2.0f, 0.1f, | |
}; | |
indices = new byte[] { | |
0, 1, 2, | |
2, 3, 0 | |
}; | |
tcs = new float[] { | |
0, 1, | |
0, 0, | |
1, 0, | |
1, 1 | |
}; | |
mesh = new VertexArray(vertices, indices, tcs); | |
} | |
public void render() { | |
Shader.TILE.enable(); | |
Shader.TILE.setUniformMat4f("vw_matrix", Matrix4f.translate(position)); | |
texture.bind(); | |
mesh.bind(); | |
Shader.TILE.setUniformMat4f("ml_matrix", ml_matrix); | |
mesh.draw(); | |
texture.unbind(); | |
mesh.unbind(); | |
} | |
public abstract void update(); | |
public float getSize() { | |
return SIZE; | |
} | |
public float getX() { | |
return position.x; | |
} | |
public float getY() { | |
return position.y; | |
} | |
public boolean isWall() { | |
return isWall; | |
} | |
} |