diff --git a/settings.bdf b/settings.bdf new file mode 100644 index 0000000..e3c37d8 Binary files /dev/null and b/settings.bdf differ diff --git a/src/projectzombie/Main.java b/src/projectzombie/Main.java index 0fca5f5..5ba0012 100644 --- a/src/projectzombie/Main.java +++ b/src/projectzombie/Main.java @@ -5,7 +5,6 @@ import java.util.Random; import mainloop.manager.MainloopManager; import projectzombie.audio.AudioEngine; import projectzombie.audio.AudioSources; -import projectzombie.cheats.Cheats; import projectzombie.display.DisplayStatsEventHandler; import projectzombie.display.DisplayWindow; import projectzombie.display.bossbar.BossBars; @@ -20,6 +19,9 @@ import projectzombie.input.KeyCallback; import projectzombie.mainloop.MainloopEventHandler; import projectzombie.menu.Menu; import projectzombie.menu.MenuMain; +import projectzombie.settings.Cheats; +import projectzombie.settings.Environment; +import projectzombie.settings.Settings; import projectzombie.tiles.LightLevelNoise; import projectzombie.time.GameTimer; import projectzombie.time.NoSleep; @@ -49,8 +51,10 @@ public class Main public static void main(String[] args) { - // Initialize the cheats + // Initialize cheats, settings, and environment + Environment.init(args); Cheats.init(args); + Settings.init(); // Load the resources Resources.loadResources(); diff --git a/src/projectzombie/display/DisplayRender.java b/src/projectzombie/display/DisplayRender.java index 3e033cf..82c32dc 100644 --- a/src/projectzombie/display/DisplayRender.java +++ b/src/projectzombie/display/DisplayRender.java @@ -1,15 +1,6 @@ package projectzombie.display; -import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT; -import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT; -import static org.lwjgl.opengl.GL11.GL_MODELVIEW; -import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; -import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; -import static org.lwjgl.opengl.GL11.glBlendFunc; -import static org.lwjgl.opengl.GL11.glClear; -import static org.lwjgl.opengl.GL11.glLoadMatrixf; -import static org.lwjgl.opengl.GL11.glMatrixMode; -import static org.lwjgl.opengl.GL11.glViewport; +import static org.lwjgl.opengl.GL33.*; import org.joml.Matrix4f; import org.lwjgl.opengl.GL; @@ -23,6 +14,7 @@ import projectzombie.init.Textures; import projectzombie.util.gl.GlHelpers; import projectzombie.util.math.vec.Vec2d; import projectzombie.util.math.vec.Vec3d; +import projectzombie.world.chunk.Chunk; public class DisplayRender { @@ -82,7 +74,10 @@ public class DisplayRender 0.0f, 1.0f, 0.0f); EntityPlayer player = Main.player; - Camera camera = new Camera(new Vec3d(player.pos.x, player.pos.y, 0), new Vec2d(player.angle, 45), 10, 1); + Camera camera = new Camera( + new Vec3d(player.pos.x, player.pos.y, 0), + new Vec2d(player.angle, 45), + 10, Chunk.RENDER_DISTANCE); Camera.camera = camera; //GlHelpers.translate(0, 0, -5); diff --git a/src/projectzombie/display/lighting/LightingManager.java b/src/projectzombie/display/lighting/LightingManager.java index ab10b1f..566b4ee 100644 --- a/src/projectzombie/display/lighting/LightingManager.java +++ b/src/projectzombie/display/lighting/LightingManager.java @@ -13,6 +13,8 @@ import projectzombie.world.layer.Layer; public class LightingManager { + public static int lightingMode = 0; + public static void update() { if(!ChunkEventHandler.loaded) return; diff --git a/src/projectzombie/entity/player/EntityPlayer.java b/src/projectzombie/entity/player/EntityPlayer.java index ef958a6..84d4982 100644 --- a/src/projectzombie/entity/player/EntityPlayer.java +++ b/src/projectzombie/entity/player/EntityPlayer.java @@ -2,7 +2,6 @@ package projectzombie.entity.player; import mainloop.task.IMainloopTask; import projectzombie.Main; -import projectzombie.cheats.Cheats; import projectzombie.display.Camera; import projectzombie.entity.Entity; import projectzombie.entity.EntityAlive; @@ -14,6 +13,7 @@ import projectzombie.entity.EntityVertical; import projectzombie.init.Textures; import projectzombie.inventory.Inventory; import projectzombie.menu.MenuDeath; +import projectzombie.settings.Cheats; import projectzombie.util.gl.GlHelpers; import projectzombie.util.gl.texture.TextureReference; import projectzombie.util.math.ItemStack; diff --git a/src/projectzombie/input/GameInput.java b/src/projectzombie/input/GameInput.java index 6c71e40..f207348 100644 --- a/src/projectzombie/input/GameInput.java +++ b/src/projectzombie/input/GameInput.java @@ -11,6 +11,7 @@ class GameInput static boolean hotbar_r = false; static boolean startButton_last = false; + static boolean backButton_last = false; static boolean moveLeft = false; static boolean moveRight = false; diff --git a/src/projectzombie/input/JoystickCallback.java b/src/projectzombie/input/JoystickCallback.java index 2f3b046..ae97a5f 100644 --- a/src/projectzombie/input/JoystickCallback.java +++ b/src/projectzombie/input/JoystickCallback.java @@ -1,15 +1,6 @@ package projectzombie.input; -import static projectzombie.input.GameInput.activateItem_last; -import static projectzombie.input.GameInput.activateTile_last; -import static projectzombie.input.GameInput.dropItem_last; -import static projectzombie.input.GameInput.fireGun; -import static projectzombie.input.GameInput.hotbar_l; -import static projectzombie.input.GameInput.hotbar_r; -import static projectzombie.input.GameInput.moveDown; -import static projectzombie.input.GameInput.moveUp; -import static projectzombie.input.GameInput.move_last; -import static projectzombie.input.GameInput.startButton_last; +import static projectzombie.input.GameInput.*; import java.nio.ByteBuffer; import java.nio.FloatBuffer; @@ -20,6 +11,7 @@ import org.lwjgl.glfw.GLFWJoystickCallbackI; import mainloop.task.IMainloopTask; import projectzombie.Main; +import projectzombie.display.DisplayWindow; import projectzombie.input.types.Input; public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask @@ -158,6 +150,8 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90; input.move(true, angle); move_last = true; + + Main.window.setMouseVisibility(false); } // Set the players moving to false @@ -169,15 +163,18 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask // Is the right x axis stick moved into a position (camera stick) if(right_x > 0.3 || right_x < -0.3) { input.camera(true, right_x); + Main.window.setMouseVisibility(false); } // Gun trigger if(right_trigger > 0.3 && !fireGun) { input.fire(true); + Main.window.setMouseVisibility(false); } // Item trigger if(left_trigger > 0.3) { + Main.window.setMouseVisibility(false); if(!activateItem_last) { activateItem_last = true; @@ -190,6 +187,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask } if(shoulder_left) { + Main.window.setMouseVisibility(false); if(!hotbar_l) { hotbar_l = true; input.hotbarShift(true, -1); @@ -201,6 +199,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask } if(shoulder_right) { + Main.window.setMouseVisibility(false); if(!hotbar_r) { hotbar_r = true; input.hotbarShift(true, 1); @@ -213,6 +212,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask // Activate tile if(button_x) { + Main.window.setMouseVisibility(false); if(!activateTile_last) { input.activateTile(true); activateTile_last = true; @@ -225,6 +225,7 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask // Drop item if(button_b) { + Main.window.setMouseVisibility(false); if(!dropItem_last) { input.itemDrop(true); dropItem_last = true; @@ -235,8 +236,21 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask dropItem_last = false; } - // Pause and unpause the game + // Back button + if(button_b) { + if(!backButton_last) { + input.back(true); + backButton_last = true; + } + } + + else if(backButton_last) { + backButton_last = false; + } + + // Pause the game if(button_start) { + Main.window.setMouseVisibility(false); if(!startButton_last) { startButton_last = true; input.pause(true); diff --git a/src/projectzombie/input/KeyCallback.java b/src/projectzombie/input/KeyCallback.java index b3ee5e7..238584b 100644 --- a/src/projectzombie/input/KeyCallback.java +++ b/src/projectzombie/input/KeyCallback.java @@ -1,26 +1,7 @@ package projectzombie.input; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_1; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_2; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_3; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_4; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_5; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_6; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_A; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_D; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_E; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_F11; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_S; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; -import static org.lwjgl.glfw.GLFW.GLFW_RELEASE; -import static projectzombie.input.GameInput.fireGun; -import static projectzombie.input.GameInput.moveDown; -import static projectzombie.input.GameInput.moveLeft; -import static projectzombie.input.GameInput.moveRight; -import static projectzombie.input.GameInput.moveUp; -import static projectzombie.input.GameInput.move_last; +import static org.lwjgl.glfw.GLFW.*; +import static projectzombie.input.GameInput.*; import org.lwjgl.glfw.GLFWKeyCallbackI; @@ -112,6 +93,16 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask else if(esc_last) { esc_last = false; } + + if(pressed) { + if(!backButton_last) { + backButton_last = true; + input.back(true); + } + } + else if(backButton_last) { + backButton_last = false; + } } if(key == GLFW_KEY_F11) { diff --git a/src/projectzombie/input/types/Input.java b/src/projectzombie/input/types/Input.java index a4dfc13..2fc1428 100644 --- a/src/projectzombie/input/types/Input.java +++ b/src/projectzombie/input/types/Input.java @@ -14,4 +14,5 @@ public interface Input public void hotbarGoto(boolean state, int pos); public void hotbarShift(boolean state, int amount); public void mousePos(Vec2d pos); + public void back(boolean state); } diff --git a/src/projectzombie/input/types/InputDeath.java b/src/projectzombie/input/types/InputDeath.java deleted file mode 100644 index f20168e..0000000 --- a/src/projectzombie/input/types/InputDeath.java +++ /dev/null @@ -1,12 +0,0 @@ -package projectzombie.input.types; - -import projectzombie.menu.gui.GUI; - -public class InputDeath extends InputGUI -{ - - public InputDeath(GUI gui) { - super(gui); - } - -} diff --git a/src/projectzombie/input/types/InputGUI.java b/src/projectzombie/input/types/InputGUI.java index 75c326b..9ed8273 100644 --- a/src/projectzombie/input/types/InputGUI.java +++ b/src/projectzombie/input/types/InputGUI.java @@ -54,5 +54,10 @@ public class InputGUI implements Input public void mousePos(Vec2d pos) { this.gui.updateMousePos(pos); } + + @Override + public void back(boolean state) { + gui.onBack(); + } } diff --git a/src/projectzombie/input/types/InputGame.java b/src/projectzombie/input/types/InputGame.java index 11f815f..6bb49c3 100644 --- a/src/projectzombie/input/types/InputGame.java +++ b/src/projectzombie/input/types/InputGame.java @@ -70,5 +70,9 @@ public class InputGame implements Input @Override public void mousePos(Vec2d pos) { } + + @Override + public void back(boolean state) { + } } diff --git a/src/projectzombie/input/types/InputGamePause.java b/src/projectzombie/input/types/InputGamePause.java deleted file mode 100644 index cc4c980..0000000 --- a/src/projectzombie/input/types/InputGamePause.java +++ /dev/null @@ -1,21 +0,0 @@ -package projectzombie.input.types; - -import projectzombie.Main; -import projectzombie.menu.MenuGame; -import projectzombie.menu.gui.GUI; - -public class InputGamePause extends InputGUI -{ - - public InputGamePause(GUI gui) { - super(gui); - } - - @Override - public void pause(boolean state) { - super.pause(state); - Main.menu = new MenuGame(); - Main.game_paused = false; - } - -} diff --git a/src/projectzombie/menu/MenuDeath.java b/src/projectzombie/menu/MenuDeath.java index 266e529..ecc9085 100644 --- a/src/projectzombie/menu/MenuDeath.java +++ b/src/projectzombie/menu/MenuDeath.java @@ -1,8 +1,9 @@ package projectzombie.menu; -import projectzombie.input.types.InputDeath; +import projectzombie.input.types.InputGUI; import projectzombie.menu.gui.GUI; -import projectzombie.menu.gui.components.LabelRespawn; +import projectzombie.menu.gui.components.ButtonGroupPause; +import projectzombie.menu.gui.components.LabelPause; import projectzombie.menu.gui.components.OverlayBackground; public class MenuDeath extends Menu @@ -15,10 +16,11 @@ public class MenuDeath extends Menu this.keepMouse = false; this.gui = new GUI(); - this.input = new InputDeath(this.gui); + this.input = new InputGUI(this.gui); gui.add(new OverlayBackground()); - gui.add(new LabelRespawn("You Died")); + gui.add(new LabelPause("You Died!")); + gui.add(new ButtonGroupPause()); } @Override diff --git a/src/projectzombie/menu/MenuGamePause.java b/src/projectzombie/menu/MenuGamePause.java index 9ee2793..57316a0 100644 --- a/src/projectzombie/menu/MenuGamePause.java +++ b/src/projectzombie/menu/MenuGamePause.java @@ -1,11 +1,13 @@ package projectzombie.menu; import projectzombie.Main; -import projectzombie.input.types.InputGamePause; +import projectzombie.input.types.InputGUI; import projectzombie.menu.gui.ButtonGroup; import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.components.ButtonBasic; -import projectzombie.menu.gui.components.LabelRespawn; +import projectzombie.menu.gui.components.ButtonGroupPause; +import projectzombie.menu.gui.components.GUIBackToMenu; +import projectzombie.menu.gui.components.LabelPause; import projectzombie.menu.gui.components.OverlayBackground; import projectzombie.util.math.vec.Vec2d; @@ -18,24 +20,12 @@ public class MenuGamePause extends Menu this.doGameRender = true; this.keepMouse = false; - this.gui = new GUI(); - this.input = new InputGamePause(this.gui); + this.gui = new GUIBackToMenu(Main.menu); + this.input = new InputGUI(this.gui); gui.add(new OverlayBackground()); - gui.add(new LabelRespawn("Game Paused")); - - ButtonGroup group = new ButtonGroup(); - - group.add(new ButtonBasic("Settings", button -> { - Main.menu = new MenuSettings(new MenuGamePause()); - })); - - group.add(new ButtonBasic("Quit", button -> { - Main.menu = new MenuMain(); - })); - - group.setPos(new Vec2d(0, -2)); - gui.add(group); + gui.add(new LabelPause("Game Paused")); + gui.add(new ButtonGroupPause()); } @Override diff --git a/src/projectzombie/menu/MenuSettings.java b/src/projectzombie/menu/MenuSettings.java index 4e7135a..349984e 100644 --- a/src/projectzombie/menu/MenuSettings.java +++ b/src/projectzombie/menu/MenuSettings.java @@ -8,8 +8,10 @@ import projectzombie.menu.gui.GUI; import projectzombie.menu.gui.Label; import projectzombie.menu.gui.components.ButtonBasic; import projectzombie.menu.gui.components.ButtonSetting; +import projectzombie.menu.gui.components.GUIBackToMenu; import projectzombie.menu.gui.components.OverlayBackground; import projectzombie.util.math.vec.Vec2d; +import projectzombie.world.chunk.Chunk; public class MenuSettings extends Menu { @@ -28,26 +30,40 @@ public class MenuSettings extends Menu ButtonGroup group = new ButtonGroup(); group.setPos(new Vec2d(-1, 4)); - group.add(new ButtonSetting(DisplayRenderUI.showFPS ? "FPS: On" : "FPS: Off", button -> { - if(DisplayRenderUI.showFPS) { - button.setText("FPS: Off"); - } else { - button.setText("FPS: On"); - } + group.add(new ButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> { DisplayRenderUI.showFPS = !DisplayRenderUI.showFPS; + button.setText("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off")); })); - group.add(new ButtonSetting(DisplayRenderUI.showPos ? "Pos Indicator: On" : "Pos Indicator: Off", - button -> { - if(DisplayRenderUI.showPos) { - button.setText("Pos Indicator: Off"); - } else { - button.setText("Pos Indicator: On"); - } + group.add(new ButtonSetting("Pos Indicator: " + (DisplayRenderUI.showPos ? "On" : "Off"), + button -> + { DisplayRenderUI.showPos = !DisplayRenderUI.showPos; + button.setText("Pos Indicator: " + (DisplayRenderUI.showPos ? "On" : "Off")); })); - gui = new GUI(); + group.add(new ButtonSetting("Render Distance: "+Chunk.RENDER_DISTANCE, button -> { + Chunk.RENDER_DISTANCE += 1; + if(Chunk.RENDER_DISTANCE > 5) { + Chunk.RENDER_DISTANCE = 1; + } + button.setText("Render Distance: "+Chunk.RENDER_DISTANCE); + })); + + /*group.add(new ButtonSetting("Dynamic Lighting: " + (LightingManager.lightingMode == 0 ? "Fast" : "Fancy"), + button -> + { + if(LightingManager.lightingMode == 0) { + LightingManager.lightingMode = 1; + + } else { + LightingManager.lightingMode = 0; + } + + button.setText("Dynamic Lighting: " + (LightingManager.lightingMode == 0 ? "Fast" : "Fancy")); + }));*/ + + gui = new GUIBackToMenu(menuOld); input = new InputGUI(gui); if(doGameRender) { diff --git a/src/projectzombie/menu/gui/Button.java b/src/projectzombie/menu/gui/Button.java index 87d8401..305d2ec 100644 --- a/src/projectzombie/menu/gui/Button.java +++ b/src/projectzombie/menu/gui/Button.java @@ -32,7 +32,7 @@ public class Button implements GUIComponent GlHelpers.pushMatrix(); GlHelpers.translate2(pos.x, pos.y); - double m = 2.5; + double m = 3; double w = textSize.x * m * 8; double h = textSize.x * m / 2; @@ -94,45 +94,43 @@ public class Button implements GUIComponent @Override public boolean checkMouseHover(Vec2d pos) { - double m = 2.5; - double w = textSize.x * m * 8 / GlHelpers.getAspectRatio(); - double h = textSize.x * m / 2; - double mx = pos.x / Main.window.getWidth() * 20 - 10; double my = pos.y / Main.window.getHeight() * 20 - 10; + double m = 3; + double w = textSize.x * m * 8 / GlHelpers.getAspectRatio(); + double h = textSize.x * m / 2; + + double w1 = 0; + double w2 = 0; + if(alignment == Alignment.LEFT) { - return ( - mx > -this.pos.x && - mx < w - this.pos.x && - my > -h - this.pos.y && - my < h - this.pos.y - ); + w1 = 0; + w2 = w; } if(alignment == Alignment.CENTRE) { - return ( - mx > -w/2 - this.pos.x && - mx < w/2 - this.pos.x && - my > -h - this.pos.y && - my < h - this.pos.y - ); + w1 = -w/2; + w2 = w/2; } if(alignment == Alignment.RIGHT) { - return ( - mx > -w - this.pos.x && - mx < -this.pos.x && - my > -h - this.pos.y && - my < h - this.pos.y - ); + w1 = -w; + w2 = 0; } - return false; + return ( + mx > w1 + this.pos.x && + mx < w2 + this.pos.x && + my > -h - this.pos.y && + my < h - this.pos.y); } @Override public void onMouseClick(Vec2d pos) { } + @Override + public void onBack() { + } } diff --git a/src/projectzombie/menu/gui/ButtonGroup.java b/src/projectzombie/menu/gui/ButtonGroup.java index ea3cdd3..75a8514 100644 --- a/src/projectzombie/menu/gui/ButtonGroup.java +++ b/src/projectzombie/menu/gui/ButtonGroup.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import projectzombie.util.math.vec.Vec2d; -public class ButtonGroup implements GUIComponent, GUIContainer +public class ButtonGroup implements GUIContainer { private ArrayList