Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Basic wall collisions are done.
  • Loading branch information
wjg12004 committed Apr 22, 2016
1 parent ccf5f50 commit 65699ea
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/game/Main.java
Expand Up @@ -124,6 +124,7 @@ public class Main implements Runnable {
if (glfwWindowShouldClose(gameWindow) == GL_TRUE) {
running = false;
}

break;
case PAUSED:
// TODO: Make a pause menu
Expand Down
11 changes: 11 additions & 0 deletions src/game/entity/Player.java
Expand Up @@ -90,11 +90,22 @@ public class Player extends Entity{
Shader.PLAYER.disable();
}

public float getX() {
return position.x;
}

public float getY() {
return position.y;
}

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

public void setPosition(float x, float y) {
this.position.x = x;
this.position.y = y;
}


}
18 changes: 16 additions & 2 deletions src/game/level/Level.java
Expand Up @@ -13,6 +13,8 @@ public class Level {
private Entity[] entities;
private float originX, originY; // Where the 'origin' of the level is the lower left of the floor area

private static final int SPRITE_PIXELS = 64;

public Level() {
currentLevel = -1;
loadLevel();
Expand Down Expand Up @@ -54,6 +56,7 @@ public class Level {
public void update() {
updateTiles();
updateEntities();
handleCollisions();
}

public void render() {
Expand Down Expand Up @@ -97,8 +100,19 @@ public class Level {
}

private void playerWallCollisions() {
boolean collided = false;
// Check for collisions, flip flag, if flag is true move player
// boolean collided = false;

// Check for collisions, flip flag, move player back
for (Tile[] tileRow : tiles) {
for (Tile tile : tileRow) {
if (tile.isWall()) {
if ((2 * tile.getX() - .5f < player.getX() + .25f && 2 * tile.getX() + .5f > player.getX() + .25f) || ((2 * tile.getX() - .5f < player.getX() - .25f && 2 * tile.getX() + .5f > player.getX() - .25f))){
if ((2 * tile.getY() - .5f < player.getY() + .25f && 2 * tile.getY() + .5f > player.getY() + .25f) || ((2 * tile.getY() - .5f < player.getY() - .25f && 2 * tile.getY() + .5f > player.getY() - .25f))){
player.setPosition(0f, 0f);
}
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions src/game/level/tiles/Tile.java
Expand Up @@ -55,5 +55,19 @@ public abstract class Tile {

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;
}
}

0 comments on commit 65699ea

Please sign in to comment.