Added fullscreen toggles, improved keyboard controls (made new ones),
added a mouse visibility option for menus
This commit is contained in:
parent
868b3481ee
commit
4a53342a73
|
|
@ -33,7 +33,7 @@ public class Main
|
||||||
public static World world;
|
public static World world;
|
||||||
public static AudioEngine audio;
|
public static AudioEngine audio;
|
||||||
public static Random rand = new Random();
|
public static Random rand = new Random();
|
||||||
public static Menu menu = new MenuGame();
|
public static Menu menu;
|
||||||
public static boolean game_paused = false;
|
public static boolean game_paused = false;
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
|
@ -80,6 +80,7 @@ public class Main
|
||||||
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
|
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
|
||||||
|
|
||||||
// Start the mainloop
|
// Start the mainloop
|
||||||
|
menu = new MenuGame();
|
||||||
mainloop.start();
|
mainloop.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import shootergame.input.JoystickCallback;
|
||||||
import shootergame.input.KeyCallback;
|
import shootergame.input.KeyCallback;
|
||||||
import shootergame.input.KeyCharCallback;
|
import shootergame.input.KeyCharCallback;
|
||||||
import shootergame.input.MouseButtonCallback;
|
import shootergame.input.MouseButtonCallback;
|
||||||
|
import shootergame.input.ScrollWheelCallback;
|
||||||
import shootergame.mainloop.MainloopEventHandler;
|
import shootergame.mainloop.MainloopEventHandler;
|
||||||
import shootergame.util.gl.GlHelpers;
|
import shootergame.util.gl.GlHelpers;
|
||||||
import shootergame.util.gl.texture.AnimationEventHandler;
|
import shootergame.util.gl.texture.AnimationEventHandler;
|
||||||
|
|
@ -21,8 +22,10 @@ public class DisplayWindow implements IMainloopTask
|
||||||
{
|
{
|
||||||
private String name;
|
private String name;
|
||||||
private long window;
|
private long window;
|
||||||
|
private long monitor;
|
||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
|
private boolean fullscreen = true;
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return this.width;
|
return this.width;
|
||||||
|
|
@ -54,7 +57,7 @@ public class DisplayWindow implements IMainloopTask
|
||||||
// Get the monitor size
|
// Get the monitor size
|
||||||
IntBuffer w = BufferUtils.createIntBuffer(1);
|
IntBuffer w = BufferUtils.createIntBuffer(1);
|
||||||
IntBuffer h = BufferUtils.createIntBuffer(1);
|
IntBuffer h = BufferUtils.createIntBuffer(1);
|
||||||
long monitor = GLFW.glfwGetPrimaryMonitor();
|
monitor = GLFW.glfwGetPrimaryMonitor();
|
||||||
GLFW.glfwGetMonitorPhysicalSize(monitor, w, h);
|
GLFW.glfwGetMonitorPhysicalSize(monitor, w, h);
|
||||||
this.width = w.get()*4;
|
this.width = w.get()*4;
|
||||||
this.height = h.get()*4;
|
this.height = h.get()*4;
|
||||||
|
|
@ -79,6 +82,7 @@ public class DisplayWindow implements IMainloopTask
|
||||||
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
|
||||||
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
|
||||||
GLFW.glfwSetJoystickCallback(JoystickCallback.JOYSTICK_CALLBACK);
|
GLFW.glfwSetJoystickCallback(JoystickCallback.JOYSTICK_CALLBACK);
|
||||||
|
GLFW.glfwSetScrollCallback(this.window, new ScrollWheelCallback());
|
||||||
|
|
||||||
// Make the cursor invisible
|
// Make the cursor invisible
|
||||||
GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
|
GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
|
||||||
|
|
@ -112,6 +116,24 @@ public class DisplayWindow implements IMainloopTask
|
||||||
this.pollEvents();
|
this.pollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleFullscreen() {
|
||||||
|
if(fullscreen) {
|
||||||
|
fullscreen = false;
|
||||||
|
GLFW.glfwSetWindowMonitor(window, 0, 1, 1, width, height, GLFW.GLFW_DONT_CARE);
|
||||||
|
} else {
|
||||||
|
fullscreen = true;
|
||||||
|
GLFW.glfwSetWindowMonitor(window, monitor, 0, 0, width, height, GLFW.GLFW_DONT_CARE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseVisibility(boolean status) {
|
||||||
|
if(status) {
|
||||||
|
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
|
||||||
|
} else {
|
||||||
|
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void swapBuffers() {
|
public void swapBuffers() {
|
||||||
GLFW.glfwSwapBuffers(this.window);
|
GLFW.glfwSwapBuffers(this.window);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,28 @@
|
||||||
package shootergame.input;
|
package shootergame.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
|
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
|
||||||
public class CursorPosCallback implements GLFWCursorPosCallbackI
|
public class CursorPosCallback implements GLFWCursorPosCallbackI
|
||||||
{
|
{
|
||||||
|
private boolean keepMouse_last = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long arg0, double arg1, double arg2) {
|
public void invoke(long window, double x, double y) {
|
||||||
// TODO Auto-generated method stub
|
if(keepMouse_last != Main.menu.keepMouse) {
|
||||||
|
Main.window.setMouseVisibility(!Main.menu.keepMouse);
|
||||||
|
keepMouse_last = Main.menu.keepMouse;
|
||||||
|
} if(!Main.menu.keepMouse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int wx = Main.window.getWidth();
|
||||||
|
int wy = Main.window.getHeight();
|
||||||
|
x = x / wx - 0.5;
|
||||||
|
y = y / wy - 0.5;
|
||||||
|
Main.menu.input.camera(true, x * 60);
|
||||||
|
GLFW.glfwSetCursorPos(window, wx / 2, wy / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,6 @@
|
||||||
package shootergame.input;
|
package shootergame.input;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
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_ENTER;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q;
|
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT_SHIFT;
|
|
||||||
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 shootergame.input.GameInput.fireGun;
|
import static shootergame.input.GameInput.fireGun;
|
||||||
import static shootergame.input.GameInput.moveDown;
|
import static shootergame.input.GameInput.moveDown;
|
||||||
import static shootergame.input.GameInput.moveLeft;
|
import static shootergame.input.GameInput.moveLeft;
|
||||||
|
|
@ -28,13 +13,14 @@ import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||||
import mainloop.task.IMainloopTask;
|
import mainloop.task.IMainloopTask;
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.input.types.Input;
|
import shootergame.input.types.Input;
|
||||||
|
import shootergame.util.math.vec.Vec2d;
|
||||||
|
|
||||||
public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
{
|
{
|
||||||
private boolean itemUse_last = false;
|
|
||||||
private boolean itemDrop_last = false;
|
private boolean itemDrop_last = false;
|
||||||
private boolean esc_last = false;
|
private boolean esc_last = false;
|
||||||
private boolean action_last = false;
|
private boolean action_last = false;
|
||||||
|
private boolean fullscreen_last = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long window, int key, int scancode, int action, int mods)
|
public void invoke(long window, int key, int scancode, int action, int mods)
|
||||||
|
|
@ -58,10 +44,6 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
moveRight = pressed;
|
moveRight = pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == GLFW_KEY_ENTER) {
|
|
||||||
fireGun = pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(key == GLFW_KEY_1 && pressed) {
|
if(key == GLFW_KEY_1 && pressed) {
|
||||||
input.hotbarGoto(true, 0);
|
input.hotbarGoto(true, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -81,18 +63,6 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
input.hotbarGoto(true, 5);
|
input.hotbarGoto(true, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == GLFW_KEY_RIGHT_SHIFT) {
|
|
||||||
if(pressed) {
|
|
||||||
if(!itemUse_last) {
|
|
||||||
itemUse_last = true;
|
|
||||||
input.itemAction(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(itemUse_last) {
|
|
||||||
itemUse_last = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(key == GLFW_KEY_E) {
|
if(key == GLFW_KEY_E) {
|
||||||
if(pressed) {
|
if(pressed) {
|
||||||
if(!action_last) {
|
if(!action_last) {
|
||||||
|
|
@ -128,6 +98,17 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
esc_last = false;
|
esc_last = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(key == GLFW_KEY_F11) {
|
||||||
|
if(pressed) {
|
||||||
|
if(!fullscreen_last) {
|
||||||
|
fullscreen_last = true;
|
||||||
|
Main.window.toggleFullscreen();
|
||||||
|
}
|
||||||
|
} else if(fullscreen_last) {
|
||||||
|
fullscreen_last = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -145,22 +126,28 @@ public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
|
||||||
{
|
{
|
||||||
Input input = Main.menu.input;
|
Input input = Main.menu.input;
|
||||||
|
|
||||||
|
Vec2d move_point = new Vec2d(0, 0);
|
||||||
|
|
||||||
if(moveUp) {
|
if(moveUp) {
|
||||||
input.move(true, 0);
|
move_point.x += 1;
|
||||||
move_last = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveDown) {
|
if(moveDown) {
|
||||||
input.move(true, 180);
|
move_point.x -= 1;
|
||||||
move_last = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveLeft) {
|
if(moveLeft) {
|
||||||
input.camera(true, -1);
|
move_point.y -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveRight) {
|
if(moveRight) {
|
||||||
input.camera(true, 1);
|
move_point.y += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(move_point.x != 0 || move_point.y != 0) {
|
||||||
|
move_last = true;
|
||||||
|
double angle = Math.toDegrees(Math.atan2(move_point.y, move_point.x));
|
||||||
|
input.move(true, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fireGun) {
|
if(fireGun) {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,24 @@
|
||||||
package shootergame.input;
|
package shootergame.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
|
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
|
||||||
public class MouseButtonCallback implements GLFWMouseButtonCallbackI
|
public class MouseButtonCallback implements GLFWMouseButtonCallbackI
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(long arg0, int arg1, int arg2, int arg3) {
|
public void invoke(long window, int button, int action, int mods)
|
||||||
// TODO Auto-generated method stub
|
{
|
||||||
|
if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
GameInput.fireGun = action == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT && action == 1) {
|
||||||
|
GameInput.activateItem_last = true;
|
||||||
|
Main.menu.input.itemAction(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package shootergame.input;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFWScrollCallbackI;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
|
|
||||||
|
public class ScrollWheelCallback implements GLFWScrollCallbackI
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(long window, double x, double y)
|
||||||
|
{
|
||||||
|
if(y > 0) {
|
||||||
|
Main.menu.input.hotbarShift(true, 1);
|
||||||
|
} if(y < 0) {
|
||||||
|
Main.menu.input.hotbarShift(true, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ public abstract class Menu
|
||||||
{
|
{
|
||||||
public boolean doGameloop;
|
public boolean doGameloop;
|
||||||
public boolean doGameRender;
|
public boolean doGameRender;
|
||||||
|
public boolean keepMouse = true;
|
||||||
public Input input;
|
public Input input;
|
||||||
|
|
||||||
public abstract void render();
|
public abstract void render();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ public class MenuDeath extends Menu
|
||||||
public MenuDeath() {
|
public MenuDeath() {
|
||||||
this.doGameloop = false;
|
this.doGameloop = false;
|
||||||
this.doGameRender = true;
|
this.doGameRender = true;
|
||||||
|
this.keepMouse = false;
|
||||||
this.input = new InputDeath();
|
this.input = new InputDeath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package shootergame.menu;
|
package shootergame.menu;
|
||||||
|
|
||||||
|
import shootergame.Main;
|
||||||
import shootergame.input.types.InputGame;
|
import shootergame.input.types.InputGame;
|
||||||
|
|
||||||
public class MenuGame extends Menu
|
public class MenuGame extends Menu
|
||||||
|
|
@ -8,6 +9,7 @@ public class MenuGame extends Menu
|
||||||
this.doGameloop = true;
|
this.doGameloop = true;
|
||||||
this.doGameRender = true;
|
this.doGameRender = true;
|
||||||
this.input = new InputGame();
|
this.input = new InputGame();
|
||||||
|
Main.window.setMouseVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ public class MenuGamePause extends Menu
|
||||||
public MenuGamePause() {
|
public MenuGamePause() {
|
||||||
this.doGameloop = false;
|
this.doGameloop = false;
|
||||||
this.doGameRender = true;
|
this.doGameRender = true;
|
||||||
|
this.keepMouse = false;
|
||||||
this.input = new InputGamePause();
|
this.input = new InputGamePause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import java.util.Random;
|
||||||
|
|
||||||
import shootergame.Main;
|
import shootergame.Main;
|
||||||
import shootergame.entity.Entity;
|
import shootergame.entity.Entity;
|
||||||
import shootergame.entity.EntityExplosion;
|
|
||||||
import shootergame.entity.EntityZombie;
|
import shootergame.entity.EntityZombie;
|
||||||
import shootergame.init.Tiles;
|
import shootergame.init.Tiles;
|
||||||
import shootergame.time.GameTimer;
|
import shootergame.time.GameTimer;
|
||||||
|
|
@ -33,10 +32,6 @@ public class LayerGenEarth extends LayerGen
|
||||||
// Get the noise generator
|
// Get the noise generator
|
||||||
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
|
OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(seed + layer.id).nextLong());
|
||||||
|
|
||||||
if(c_pos.x == 0 && c_pos.y == 0) {
|
|
||||||
chunk.spawnEntity(new EntityExplosion(new Vec2d(1, 1), 10, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop over the layer dimensions and create land
|
// Loop over the layer dimensions and create land
|
||||||
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
|
for(int x=0;x<Chunk.CHUNK_SIZE.mx;x++) {
|
||||||
for(int y=0;y<Chunk.CHUNK_SIZE.my;y++)
|
for(int y=0;y<Chunk.CHUNK_SIZE.my;y++)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue