diff --git a/src/game/Main.java b/src/game/Main.java index fd3180d..cd360df 100644 --- a/src/game/Main.java +++ b/src/game/Main.java @@ -12,8 +12,10 @@ import org.lwjgl.opengl.GL11; import game.graphics.Shader; import game.input.Input; +import game.input.Mouse; import game.level.Level; import game.math.Matrix4f; +import game.menus.*; public class Main implements Runnable { @@ -27,7 +29,8 @@ public class Main implements Runnable { //Must be explicitly declared to avoid being garbage collected - private Input input = new Input(); + private Input input; + private Mouse mouse; public void start() { running = true; @@ -51,9 +54,13 @@ public class Main implements Runnable { return; } + mouse = new Mouse(gameWindow); + input = new Input(); + GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(gameWindow, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2); glfwSetKeyCallback(gameWindow, input); + glfwSetCursorPosCallback(gameWindow, mouse); glfwMakeContextCurrent(gameWindow); glfwShowWindow(gameWindow); GL.createCapabilities(); @@ -88,6 +95,7 @@ public class Main implements Runnable { while (running) { switch (gameState) { case MAIN_MENU: + // TODO: Make a main menu gameState = State.IN_GAME; break; case IN_GAME: @@ -118,6 +126,7 @@ public class Main implements Runnable { } break; case PAUSED: + // TODO: Make a pause menu System.out.println("paused it"); gameState = State.IN_GAME; break; diff --git a/src/game/input/Mouse.java b/src/game/input/Mouse.java new file mode 100644 index 0000000..fe69f70 --- /dev/null +++ b/src/game/input/Mouse.java @@ -0,0 +1,33 @@ +package game.input; + +import static org.lwjgl.glfw.GLFW.*; + +import org.lwjgl.glfw.GLFWCursorPosCallback; + +public class Mouse extends GLFWCursorPosCallback { + + private double xPos, yPos; + private long window; + + public Mouse(long window) { + this.window = window; + } + + @Override + public void invoke(long window, double xPos, double yPos) { + this.xPos = xPos; + this.yPos = yPos; + } + + public double getX() { + return xPos; + } + + public double getY() { + return yPos; + } + + public boolean leftClicked() { + return (1 == glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1)); + } +} diff --git a/src/game/level/Level.java b/src/game/level/Level.java index 28533ea..8953281 100644 --- a/src/game/level/Level.java +++ b/src/game/level/Level.java @@ -3,7 +3,6 @@ package game.level; import game.entity.Entity; import game.entity.Player; import game.level.tiles.*; -import game.level.tiles.Tile; public class Level { @@ -100,6 +99,6 @@ public class Level { private void playerWallCollisions() { boolean collided = false; - // Check for collisions, flip flag, move player + // Check for collisions, flip flag, move player back } } diff --git a/src/game/menus/Button.java b/src/game/menus/Button.java new file mode 100644 index 0000000..56c3b3c --- /dev/null +++ b/src/game/menus/Button.java @@ -0,0 +1,77 @@ +package game.menus; + +import java.awt.Rectangle; + +import org.lwjgl.opengl.GL11; + +import game.input.Mouse; + +public class Button { + + int xPos, yPos, width, height; + String text; + + boolean clickable = true; + boolean visible = true; + + private Mouse mouse; + private Rectangle collisionRect; + + public Button(int xPos, int yPos, int width, int height, String text, Mouse mouse) { + this.xPos = xPos; + this.yPos = yPos; + this.width = width; + this.height = height; + this.text = text; + this.mouse = mouse; + + collisionRect = new Rectangle(); + collisionRect.x = xPos; + collisionRect.y = yPos; + collisionRect.height = height; + collisionRect.width = width; + + + } + + public void draw() { + if (visible) { + if (mouseOver() && clickable) { + GL11.glColor3f(.7f, .7f, .7f); + + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex2d(xPos - 1, yPos + 1); + GL11.glVertex2d(xPos + width + 1, yPos + 1); + GL11.glVertex2d(xPos + width + 1, yPos + height - 1); + GL11.glVertex2d(xPos - 1, yPos + height - 1); + GL11.glEnd(); + + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex2d(xPos + 1, yPos - 1); + GL11.glVertex2d(xPos + width - 1, yPos - 1); + GL11.glVertex2d(xPos + width - 1, yPos + height + 1); + GL11.glVertex2d(xPos + 1, yPos + height + 1); + GL11.glEnd(); + } + } + } + + public boolean clicked() { + return collisionRect.contains(mouse.getX(), mouse.getY()) && mouse.leftClicked(); + + } + + public boolean mouseOver() { + return collisionRect.contains(mouse.getX(), mouse.getY()); + } + + public void setClickable(boolean clickable) { + this.clickable = clickable; + } + + public void setVisible(boolean visible) { + this.visible = visible; + } + + +}