Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Menu and game state backbone is done, just need to make the main/paus…
…e menus
  • Loading branch information
wjg12004 committed Apr 19, 2016
1 parent ff5fb9a commit 7099989
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
66 changes: 42 additions & 24 deletions src/game/Main.java
Expand Up @@ -5,6 +5,7 @@ import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.system.MemoryUtil.*;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
Expand All @@ -22,6 +23,8 @@ public class Main implements Runnable {
private Thread gameThread;
private long gameWindow;
private Level level;
private static State gameState = State.MAIN_MENU;


//Must be explicitly declared to avoid being garbage collected
private Input input = new Input();
Expand Down Expand Up @@ -83,30 +86,41 @@ public class Main implements Runnable {
int currentFrames = 0;

while (running) {
GL11.glClearColor(.753f, .753f, .753f, .753f);

// Frames/Updates per second counter and limiter
long currentTime = System.nanoTime();
deltaT += (currentTime - prevTime) / nanoSecConversion;
prevTime = currentTime;
if (deltaT >= 1.0) {
update();
currentUpdates++;
deltaT--;
}
render();
currentFrames++;
// If longer than one second has passed
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println("Updates Per Second: " + currentUpdates);
System.out.println("Frames Per Second: " + currentFrames);
currentUpdates = 0;
currentFrames = 0;
}

if (glfwWindowShouldClose(gameWindow) == GL_TRUE) {
running = false;
switch (gameState) {
case MAIN_MENU:
gameState = State.IN_GAME;
break;
case IN_GAME:
GL11.glClearColor(.753f, .753f, .753f, .753f);

// Frames/Updates per second counter and limiter
long currentTime = System.nanoTime();
deltaT += (currentTime - prevTime) / nanoSecConversion;
prevTime = currentTime;
if (deltaT >= 1.0) {
update();
currentUpdates++;
deltaT--;
}
render();
currentFrames++;
// If longer than one second has passed
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println("Updates Per Second: " + currentUpdates);
System.out.println("Frames Per Second: " + currentFrames);
currentUpdates = 0;
currentFrames = 0;
}

if (glfwWindowShouldClose(gameWindow) == GL_TRUE) {
running = false;
}
break;
case PAUSED:
System.out.println("paused it");
gameState = State.IN_GAME;
break;
}
}

Expand All @@ -117,6 +131,10 @@ public class Main implements Runnable {
public void update() {
glfwPollEvents();
level.update();

if (Input.keys[GLFW.GLFW_KEY_SPACE]) {
gameState = State.PAUSED;
}
}

public void render() {
Expand Down
5 changes: 5 additions & 0 deletions src/game/State.java
@@ -0,0 +1,5 @@
package game;

public enum State {
MAIN_MENU, IN_GAME, PAUSED;
}
1 change: 1 addition & 0 deletions src/game/level/Level.java
Expand Up @@ -90,6 +90,7 @@ public class Level {
}
}

// TODO: This
private void handleCollisions() {
playerWallCollisions();
// Player-entity collisions
Expand Down

0 comments on commit 7099989

Please sign in to comment.