From 70999890e50f20deeb1fc2fdb8065cc8379c04ae Mon Sep 17 00:00:00 2001 From: Billy Gallagher Date: Mon, 18 Apr 2016 22:19:51 -0400 Subject: [PATCH] Menu and game state backbone is done, just need to make the main/pause menus --- src/game/Main.java | 66 +++++++++++++++++++++++++-------------- src/game/State.java | 5 +++ src/game/level/Level.java | 1 + 3 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 src/game/State.java diff --git a/src/game/Main.java b/src/game/Main.java index c5e18be..fd3180d 100644 --- a/src/game/Main.java +++ b/src/game/Main.java @@ -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; @@ -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(); @@ -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; } } @@ -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() { diff --git a/src/game/State.java b/src/game/State.java new file mode 100644 index 0000000..bebfc6e --- /dev/null +++ b/src/game/State.java @@ -0,0 +1,5 @@ +package game; + +public enum State { + MAIN_MENU, IN_GAME, PAUSED; +} diff --git a/src/game/level/Level.java b/src/game/level/Level.java index ce9c37a..28533ea 100644 --- a/src/game/level/Level.java +++ b/src/game/level/Level.java @@ -90,6 +90,7 @@ public class Level { } } + // TODO: This private void handleCollisions() { playerWallCollisions(); // Player-entity collisions