Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Basic tile rendering complete. Next up should be collision checking, …
…but we'll see if I can focus on one thing for that long.
- Loading branch information
Showing
22 changed files
with
207 additions
and
104 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ in DATA | |
vec3 position; | ||
} fs_in; | ||
|
||
uniform vec2 player; | ||
uniform sampler2D tex; | ||
|
||
void main() | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package game.entity; | ||
|
||
import game.graphics.Texture; | ||
import game.graphics.VertexArray; | ||
import game.math.Vector3f; | ||
|
||
public abstract class Entity { | ||
|
||
protected float SIZE; | ||
protected Vector3f position = new Vector3f(); | ||
protected float speed; | ||
|
||
protected VertexArray mesh; | ||
protected Texture texture; | ||
protected float[] vertices; | ||
protected byte[] indices; | ||
protected float[] tcs; | ||
|
||
public abstract void update(); | ||
public abstract void render(); | ||
|
||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,104 @@ | ||
package game.level; | ||
|
||
import game.entity.Entity; | ||
import game.entity.Player; | ||
import game.graphics.Shader; | ||
import game.graphics.Texture; | ||
import game.graphics.VertexArray; | ||
import game.level.tiles.*; | ||
import game.level.tiles.Tile; | ||
|
||
public class Level { | ||
// number of tiles | ||
// private int width, height; | ||
|
||
private Player player; | ||
private int currentLevel; | ||
private int width, height; // Number of tiles | ||
private Tile[][] tiles; | ||
private Entity[] entities; | ||
private float originX, originY; // Where the 'origin' of the level is the lower left of the floor area | ||
|
||
public Level() { | ||
float[] vertices = new float[] { | ||
-10.0f, -10.0f * 9.0f / 16.0f, 0.0f, | ||
-10.0f, 10.0f * 9.0f / 16.0f, 0.0f, | ||
0.0f, 10.0f * 9.0f / 16.0f, 0.0f, | ||
0.0f, -10.0f * 9.0f / 16.0f, 0.0f, | ||
}; | ||
currentLevel = -1; | ||
loadLevel(); | ||
} | ||
|
||
private void loadLevel() { | ||
|
||
byte[] indices = new byte[] { | ||
0, 1, 2, | ||
2, 3, 0 | ||
}; | ||
// This is a test level | ||
if (currentLevel == -1) { | ||
width = 7; | ||
height = 7; | ||
tiles = new Tile[width][height]; | ||
|
||
float[] tcs = new float[] { | ||
0, 1, | ||
0, 0, | ||
1, 0, | ||
1, 1 | ||
}; | ||
|
||
player = new Player(); | ||
|
||
// Tile coordinates are double entity coordinates, i.e. the entity at (1, 1) is on the tile at (2, 2) | ||
originX = -1.5f; | ||
originY = -1.5f; | ||
|
||
// Load entities and positions, load into array | ||
player = new Player(0f, 0f); | ||
entities = new Entity[1]; | ||
entities[0] = player; | ||
|
||
// Load tiles. Sample, 5 x 5 grid of StoneFloor surrounded by StoneWalls | ||
Tile.create(); | ||
for (int y = 0; y < width; y++) { | ||
for (int x = 0; x < height; x++) { | ||
float convertX = x/2f; // Tile coordinates are double entity coordinates | ||
float convertY = y/2f; | ||
if (y == 0 || y == height - 1 || x == 0 || x == width - 1) { | ||
tiles[x][y] = new StoneWall(convertX + originX, convertY + originY); | ||
} else { | ||
tiles[x][y] = new StoneFloor(convertX + originX, convertY + originY); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public void update() { | ||
// tile update | ||
// player update | ||
// enemy update | ||
|
||
player.update(); | ||
updateTiles(); | ||
updateEntities(); | ||
} | ||
|
||
public void render() { | ||
// render tiles | ||
// render player | ||
// render other entities | ||
|
||
player.render(); | ||
renderTiles(); | ||
renderEntities(); | ||
} | ||
|
||
private void updateTiles() { | ||
for (Tile[] tileRow : tiles) { | ||
for (Tile tile : tileRow) { | ||
tile.update(); | ||
} | ||
} | ||
} | ||
|
||
private void updateEntities() { | ||
for (Entity entity : entities) { | ||
entity.update(); | ||
} | ||
} | ||
|
||
private void renderTiles() { | ||
for (Tile[] tileRow : tiles) { | ||
for (Tile tile : tileRow) { | ||
tile.render(); | ||
} | ||
} | ||
} | ||
|
||
private void renderEntities() { | ||
for (Entity entity : entities) { | ||
entity.render(); | ||
} | ||
} | ||
|
||
private void handleCollisions() { | ||
playerWallCollisions(); | ||
// Player-entity collisions | ||
// Entity-wall collisions | ||
} | ||
|
||
private void playerWallCollisions() { | ||
boolean collided = false; | ||
|
||
// Check for collisions, flip flag, move player | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package game.level.tiles; | ||
|
||
import game.graphics.Texture; | ||
import game.math.Matrix4f; | ||
|
||
public class StoneFloor extends Tile{ | ||
|
||
public StoneFloor(float x, float y) { | ||
position.x = x; | ||
position.y = y; | ||
texture = new Texture("res/sprites/stoneFloor.png"); | ||
ml_matrix = Matrix4f.translate(position); | ||
isWall = false; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
return; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package game.level.tiles; | ||
|
||
import game.graphics.Texture; | ||
import game.math.Matrix4f; | ||
|
||
public class StoneWall extends Tile { | ||
|
||
public StoneWall(float x, float y) { | ||
position.x = x; | ||
position.y = y; | ||
texture = new Texture("res/sprites/stoneWall.png"); | ||
ml_matrix = Matrix4f.translate(position); | ||
isWall = true; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
return; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.