Improved the controls; made them more changable and fixed issues with

the keyboard and the controller being used together to cheat (fast speed
and fast gun)
This commit is contained in:
josua 2019-09-22 10:55:00 +10:00
parent d88b433b11
commit ef6fe56c89
15 changed files with 614 additions and 376 deletions

View File

@ -15,9 +15,10 @@ import shootergame.init.Resources;
import shootergame.init.Sounds;
import shootergame.init.Textures;
import shootergame.input.JoystickCallback;
import shootergame.input.KeyCallback;
import shootergame.mainloop.MainloopEventHandler;
import shootergame.menu.Menu;
import shootergame.menu.MenuNone;
import shootergame.menu.MenuGame;
import shootergame.tiles.LightLevelNoise;
import shootergame.time.GameTimer;
import shootergame.world.World;
@ -31,7 +32,7 @@ public class Main
public static World world;
public static AudioEngine audio;
public static Random rand = new Random();
public static Menu menu = new MenuNone();
public static Menu menu = new MenuGame();
public static boolean game_paused = false;
public static void main(String[] args)
@ -58,6 +59,7 @@ public class Main
mainloop.register(JoystickCallback.JOYSTICK_CALLBACK);
mainloop.register(new LightLevelNoise());
mainloop.register(new GameTimer());
mainloop.register(new KeyCallback());
// Create the display
window = new DisplayWindow("ShooterGame");

View File

@ -49,52 +49,56 @@ public class DisplayRender
// Bind the texmap
Textures.texmap.bindTexture();
GlHelpers.pushMatrix();
if(Main.menu.doGameRender)
{
// Set matrix mode
glMatrixMode(GL_MODELVIEW);
// Push the matrix
GlHelpers.pushMatrix();
TransparentObjects.clear();
{
// Set matrix mode
glMatrixMode(GL_MODELVIEW);
// Set the colour to white
GlHelpers.color4(1, 1, 1, 1);
TransparentObjects.clear();
// Create a matrix
Matrix4f m = new Matrix4f();
// Set the colour to white
GlHelpers.color4(1, 1, 1, 1);
// Set the perspective
m.setPerspective((float) Math.toRadians(45.0f), ((float)w)/((float)h), 0.01f, 100.0f);
try (MemoryStack stack = MemoryStack.stackPush()) {
glLoadMatrixf(m.get(stack.mallocFloat(16)));
// Create a matrix
Matrix4f m = new Matrix4f();
// Set the perspective
m.setPerspective((float) Math.toRadians(45.0f), ((float)w)/((float)h), 0.01f, 100.0f);
try (MemoryStack stack = MemoryStack.stackPush()) {
glLoadMatrixf(m.get(stack.mallocFloat(16)));
}
// Set the camera angle
m.setLookAt(0.0f, 0.0f, 10.0f,
0.0f, 0.0f, 0.0f,
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 = camera;
//GlHelpers.translate(0, 0, -5);
GlHelpers.rotate(camera.angle.y, 1, 0, 0);
GlHelpers.rotate(camera.angle.x, 0, 0, 1);
GlHelpers.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z);
// Process all the light sources
LightingManager.update();
// Render the world and the player
Main.world.render(camera);
player.chunk = Main.world.getLayer().getChunk(player.pos);
player.doRender(player.pos, camera);
// Render the sorted transparent objects
TransparentObjects.render(camera);
GlHelpers.popMatrix();
}
// Set the camera angle
m.setLookAt(0.0f, 0.0f, 10.0f,
0.0f, 0.0f, 0.0f,
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 = camera;
//GlHelpers.translate(0, 0, -5);
GlHelpers.rotate(camera.angle.y, 1, 0, 0);
GlHelpers.rotate(camera.angle.x, 0, 0, 1);
GlHelpers.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z);
// Process all the light sources
LightingManager.update();
// Render the world and the player
Main.world.render(camera);
player.chunk = Main.world.getLayer().getChunk(player.pos);
player.doRender(player.pos, camera);
// Render the sorted transparent objects
TransparentObjects.render(camera);
GlHelpers.popMatrix();
}
// Render the user interface

View File

@ -27,122 +27,130 @@ public class DisplayRenderUI
// Get some text settings
Vec2d text_size = new Vec2d(0.5, 0.2);
// Render the fps and the position
// Render the fps
GlHelpers.pushMatrix();
GlHelpers.translate(-9.5, 9.5, 0);
GlHelpers.color3(1, 1, 0);
Text.render("FPS: " + DisplayStatsEventHandler.fps, text_size);
GlHelpers.translate(0, -0.5, 0);
Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, text_size);
GlHelpers.color3(1, 1, 1);
GlHelpers.popMatrix();
// Render the healthbar
double max_health = player.maxHealth();
double a = 1 - (player.getHealth() / max_health);
TextureReference health_fg = Textures.UI_HEALTH_FG;
TextureReference health_bg = Textures.UI_HEALTH_BG;
GlHelpers.begin();
health_bg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0);
health_bg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0);
health_bg.texCoord(1, 0); GlHelpers.vertex2(3.2, -9.0);
health_bg.texCoord(1, 1); GlHelpers.vertex2(3.2, -8.0);
health_fg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0);
health_fg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0);
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(3.2-a*6.4, -9.0);
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(3.2-a*6.4, -8.0);
GlHelpers.end();
// Display the amount of ammo left, and the defence and gun level
GlHelpers.pushMatrix();
TextureReference ammo_tex = Textures.ITEM_AMMO_BOX;
TextureReference gunlevel_tex = Textures.UI_GUN_LEVEL;
TextureReference deflevel_tex = Textures.UI_DEFENCE_LEVEL;
GlHelpers.begin();
ammo_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -8.5);
ammo_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -7.0);
ammo_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -7.0);
ammo_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -8.5);
gunlevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -6.5);
gunlevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -5.0);
gunlevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -5.0);
gunlevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -6.5);
deflevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -4.5);
deflevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -3.0);
deflevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -3.0);
deflevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -4.5);
GlHelpers.end();
GlHelpers.translate(-8.5, -9, 0);
Text.render(Integer.toString(player.ammo), text_size);
GlHelpers.translate(0, 2.5, 0);
Text.render(Integer.toString(player.gun_level), text_size);
GlHelpers.translate(0, 2, 0);
Text.render(Integer.toString(player.defence_level), text_size);
GlHelpers.popMatrix();
// Display all the items in the players inventory
TextureReference slots_tex = Textures.UI_ITEM_SLOTS;
GlHelpers.begin();
slots_tex.texCoord(0, 1); GlHelpers.vertex2(9.5, -9.4);
slots_tex.texCoord(0, 0); GlHelpers.vertex2(9.5, -7.6);
slots_tex.texCoord(1, 0); GlHelpers.vertex2(3.5, -7.6);
slots_tex.texCoord(1, 1); GlHelpers.vertex2(3.5, -9.4);
GlHelpers.end();
// Render the players active slot
TextureReference hotbar_slot_tex = Textures.UI_ACTIVE_SLOT;
GlHelpers.begin();
hotbar_slot_tex.texCoord(0, 1); GlHelpers.vertex2(4.55 + player.inventory_hand, -9.45);
hotbar_slot_tex.texCoord(0, 0); GlHelpers.vertex2(4.55 + player.inventory_hand, -7.55);
hotbar_slot_tex.texCoord(1, 0); GlHelpers.vertex2(3.45 + player.inventory_hand, -7.55);
hotbar_slot_tex.texCoord(1, 1); GlHelpers.vertex2(3.45 + player.inventory_hand, -9.45);
GlHelpers.end();
// Get the players inventory
Inventory player_inv = player.getInventory();
// Render the players inventory
for(int i=0;i<6;i++)
if(Main.menu.doGameRender)
{
ItemStack player_item = player_inv.getItem(i);
// Render the fps and the position
GlHelpers.pushMatrix();
GlHelpers.translate(-9.5, 9, 0);
GlHelpers.color3(1, 1, 0);
Text.render("x: " + (int) player.pos.x + ", y: " + (int) player.pos.y, text_size);
GlHelpers.color3(1, 1, 1);
GlHelpers.popMatrix();
if(!player_item.isEmpty())
// Render the healthbar
double max_health = player.maxHealth();
double a = 1 - (player.getHealth() / max_health);
TextureReference health_fg = Textures.UI_HEALTH_FG;
TextureReference health_bg = Textures.UI_HEALTH_BG;
GlHelpers.begin();
health_bg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0);
health_bg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0);
health_bg.texCoord(1, 0); GlHelpers.vertex2(3.2, -9.0);
health_bg.texCoord(1, 1); GlHelpers.vertex2(3.2, -8.0);
health_fg.texCoord(0, 1); GlHelpers.vertex2(-3.2, -8.0);
health_fg.texCoord(0, 0); GlHelpers.vertex2(-3.2, -9.0);
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(3.2-a*6.4, -9.0);
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(3.2-a*6.4, -8.0);
GlHelpers.end();
// Display the amount of ammo left, and the defence and gun level
GlHelpers.pushMatrix();
TextureReference ammo_tex = Textures.ITEM_AMMO_BOX;
TextureReference gunlevel_tex = Textures.UI_GUN_LEVEL;
TextureReference deflevel_tex = Textures.UI_DEFENCE_LEVEL;
GlHelpers.begin();
ammo_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -8.5);
ammo_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -7.0);
ammo_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -7.0);
ammo_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -8.5);
gunlevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -6.5);
gunlevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -5.0);
gunlevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -5.0);
gunlevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -6.5);
deflevel_tex.texCoord(0, 1); GlHelpers.vertex2(-9.5, -4.5);
deflevel_tex.texCoord(0, 0); GlHelpers.vertex2(-9.5, -3.0);
deflevel_tex.texCoord(1, 0); GlHelpers.vertex2(-8.5, -3.0);
deflevel_tex.texCoord(1, 1); GlHelpers.vertex2(-8.5, -4.5);
GlHelpers.end();
GlHelpers.translate(-8.5, -9, 0);
Text.render(Integer.toString(player.ammo), text_size);
GlHelpers.translate(0, 2.5, 0);
Text.render(Integer.toString(player.gun_level), text_size);
GlHelpers.translate(0, 2, 0);
Text.render(Integer.toString(player.defence_level), text_size);
GlHelpers.popMatrix();
// Display all the items in the players inventory
TextureReference slots_tex = Textures.UI_ITEM_SLOTS;
GlHelpers.begin();
slots_tex.texCoord(0, 1); GlHelpers.vertex2(9.5, -9.4);
slots_tex.texCoord(0, 0); GlHelpers.vertex2(9.5, -7.6);
slots_tex.texCoord(1, 0); GlHelpers.vertex2(3.5, -7.6);
slots_tex.texCoord(1, 1); GlHelpers.vertex2(3.5, -9.4);
GlHelpers.end();
// Render the players active slot
TextureReference hotbar_slot_tex = Textures.UI_ACTIVE_SLOT;
GlHelpers.begin();
hotbar_slot_tex.texCoord(0, 1); GlHelpers.vertex2(4.55 + player.inventory_hand, -9.45);
hotbar_slot_tex.texCoord(0, 0); GlHelpers.vertex2(4.55 + player.inventory_hand, -7.55);
hotbar_slot_tex.texCoord(1, 0); GlHelpers.vertex2(3.45 + player.inventory_hand, -7.55);
hotbar_slot_tex.texCoord(1, 1); GlHelpers.vertex2(3.45 + player.inventory_hand, -9.45);
GlHelpers.end();
// Get the players inventory
Inventory player_inv = player.getInventory();
// Render the players inventory
for(int i=0;i<6;i++)
{
player_item.item.render(new Vec2d(3.5 + i, -9.2), new Vec2d(1, 1.5));
ItemStack player_item = player_inv.getItem(i);
if(!player_item.isEmpty())
{
player_item.item.render(new Vec2d(3.5 + i, -9.2), new Vec2d(1, 1.5));
GlHelpers.pushMatrix();
GlHelpers.translate(3.8 + i, -9.2, 0);
Text.render(Integer.toString(player_item.count), text_size);
GlHelpers.popMatrix();
}
}
// Render the active slots text
ItemStack item_active = player_inv.getItem(player.inventory_hand);
if(!item_active.isEmpty())
{
GlHelpers.pushMatrix();
GlHelpers.translate(3.8 + i, -9.2, 0);
Text.render(Integer.toString(player_item.count), text_size);
GlHelpers.translate(3.8, -7.4, 0);
Text.render(item_active.item.getName(item_active.meta), text_size);
GlHelpers.popMatrix();
}
}
// Render the active slots text
ItemStack item_active = player_inv.getItem(player.inventory_hand);
if(!item_active.isEmpty())
{
GlHelpers.pushMatrix();
GlHelpers.translate(3.8, -7.4, 0);
Text.render(item_active.item.getName(item_active.meta), text_size);
GlHelpers.popMatrix();
// Render the boss bars
BossBars.render();
}
// Render the boss bars
BossBars.render();
// Render the loaded menu
Main.menu.render();
}

View File

@ -0,0 +1,20 @@
package shootergame.input;
class GameInput
{
static boolean activateItem_last = false;
static boolean activateTile_last = false;
static boolean dropItem_last = false;
static boolean move_last = false;
static boolean hotbar_l = false;
static boolean hotbar_r = false;
static boolean startButton_last = false;
static boolean moveLeft = false;
static boolean moveRight = false;
static boolean moveUp = false;
static boolean moveDown = false;
static boolean fireGun = false;
}

View File

@ -4,29 +4,20 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import static shootergame.input.GameInput.*;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWJoystickCallbackI;
import mainloop.task.IMainloopTask;
import shootergame.Main;
import shootergame.menu.MenuNone;
import shootergame.menu.MenuPause;
import shootergame.util.math.MathHelpers;
import shootergame.input.types.Input;
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
{
public static final JoystickCallback JOYSTICK_CALLBACK = new JoystickCallback();
private ArrayList<Integer> connections = new ArrayList<Integer>();
private static boolean activateItem_last = false;
private static boolean activateTile_last = false;
private static boolean dropItem_last = false;
private static boolean hotbar_l = false;
private static boolean hotbar_r = false;
private static boolean startButton_last = false;
@Override
public void invoke(int jid, int event)
{
@ -150,111 +141,97 @@ public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
dpad_down = buttons.get(14) == 1 || buttons.get(17) == 1 || dpad_down;
}
// Only check for these input commands if the game isn't paused
if(!Main.game_paused)
Input input = Main.menu.input;
// Is the left stick moved into a position (movement stick)
if((left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3) && !moveUp && !moveDown)
{
// Is the left stick moved into a position (movement stick)
if(left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3)
// Get the the angle
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
input.move(true, angle);
move_last = true;
}
// Set the players moving to false
else if(move_last && !moveUp && !moveDown) {
move_last = false;
input.move(false, 0);
}
// 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);
}
// Gun trigger
if(right_trigger > 0.3 && !fireGun) {
input.fire(true);
}
// Item trigger
if(left_trigger > 0.3) {
if(!activateItem_last)
{
// Get the the angle
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
// Move the player in the left sticks angle
Main.player.moveTowards(angle);
// Set the players moving to true
Main.player.moving = true;
activateItem_last = true;
input.itemAction(true);
}
}
// Set the players moving to false
else Main.player.moving = false;
else {
activateItem_last = false;
}
// Is the right x axis stick moved into a position (camera stick)
if(right_x > 0.3 || right_x < -0.3) {
Main.player.angle += right_x;
if(shoulder_left) {
if(!hotbar_l) {
hotbar_l = true;
input.hotbarShift(true, -1);
}
}
// Gun trigger
if(right_trigger > 0.3) {
Main.player.fireBullet(0);
}
else if(hotbar_l) {
hotbar_l = false;
}
// Item trigger
if(left_trigger > 0.3) {
if(!activateItem_last)
{
activateItem_last = true;
Main.player.activateItem();
}
if(shoulder_right) {
if(!hotbar_r) {
hotbar_r = true;
input.hotbarShift(true, 1);
}
}
else {
activateItem_last = false;
}
else if(hotbar_r) {
hotbar_r = false;
}
if(shoulder_left) {
if(!hotbar_l) {
hotbar_l = true;
Main.player.inventory_hand -= 1;
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
}
// Activate tile
if(button_x) {
if(!activateTile_last) {
input.activateTile(true);
activateTile_last = true;
}
}
else if(hotbar_l) {
hotbar_l = false;
}
else if(activateTile_last) {
activateTile_last = false;
}
if(shoulder_right) {
if(!hotbar_r) {
hotbar_r = true;
Main.player.inventory_hand += 1;
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
}
// Drop item
if(button_b) {
if(!dropItem_last) {
input.itemDrop(true);
dropItem_last = true;
}
}
else if(hotbar_r) {
hotbar_r = false;
}
// Activate tile
if(button_x) {
if(!activateTile_last) {
Main.player.activateTile();
activateTile_last = true;
}
}
else if(activateTile_last) {
activateTile_last = false;
}
// Drop item
if(button_b) {
if(!dropItem_last) {
Main.player.dropItem();
dropItem_last = true;
}
}
else if(dropItem_last) {
dropItem_last = false;
}
else if(dropItem_last) {
dropItem_last = false;
}
// Pause and unpause the game
if(button_start) {
if(!startButton_last) {
startButton_last = true;
if(Main.game_paused) {
Main.menu = new MenuNone();
Main.game_paused = false;
}
else {
Main.menu = new MenuPause();
Main.game_paused = true;
}
input.pause(true);
}
}

View File

@ -1,29 +1,15 @@
package shootergame.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_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 org.lwjgl.glfw.GLFW.*;
import static shootergame.input.GameInput.*;
import org.lwjgl.glfw.GLFWKeyCallbackI;
import mainloop.task.IMainloopTask;
import shootergame.Main;
import shootergame.menu.MenuNone;
import shootergame.menu.MenuPause;
import shootergame.input.types.Input;
public class KeyCallback implements GLFWKeyCallbackI
public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
{
private boolean itemUse_last = false;
private boolean itemDrop_last = false;
@ -33,112 +19,89 @@ public class KeyCallback implements GLFWKeyCallbackI
@Override
public void invoke(long window, int key, int scancode, int action, int mods)
{
Input input = Main.menu.input;
boolean pressed = ! ( action == GLFW_RELEASE );
if(!Main.game_paused && !Main.player.dead && !Main.player.in_animation)
{
if(key == GLFW_KEY_W) {
Main.player.MOVE_FORWARD = pressed;
}
if(key == GLFW_KEY_W) {
moveUp = pressed;
}
if(key == GLFW_KEY_S) {
Main.player.MOVE_BACKWARD = pressed;
}
if(key == GLFW_KEY_S) {
moveDown = pressed;
}
if(key == GLFW_KEY_A) {
Main.player.MOVE_LEFT = pressed;
}
if(key == GLFW_KEY_A) {
moveLeft = pressed;
}
if(key == GLFW_KEY_D) {
Main.player.MOVE_RIGHT = pressed;
}
if(key == GLFW_KEY_D) {
moveRight = pressed;
}
if(key == GLFW_KEY_ENTER) {
Main.player.GUN = pressed;
}
if(key == GLFW_KEY_ENTER) {
fireGun = pressed;
}
if(key == GLFW_KEY_1 && pressed) {
Main.player.inventory_hand = 0;
}
if(key == GLFW_KEY_2 && pressed) {
Main.player.inventory_hand = 1;
}
if(key == GLFW_KEY_3 && pressed) {
Main.player.inventory_hand = 2;
}
if(key == GLFW_KEY_4 && pressed) {
Main.player.inventory_hand = 3;
}
if(key == GLFW_KEY_5 && pressed) {
Main.player.inventory_hand = 4;
}
if(key == GLFW_KEY_6 && pressed) {
Main.player.inventory_hand = 5;
}
if(key == GLFW_KEY_1 && pressed) {
input.hotbarGoto(true, 0);
}
if(key == GLFW_KEY_2 && pressed) {
input.hotbarGoto(true, 1);
}
if(key == GLFW_KEY_3 && pressed) {
input.hotbarGoto(true, 2);
}
if(key == GLFW_KEY_4 && pressed) {
input.hotbarGoto(true, 3);
}
if(key == GLFW_KEY_5 && pressed) {
input.hotbarGoto(true, 4);
}
if(key == GLFW_KEY_6 && pressed) {
input.hotbarGoto(true, 5);
}
if(key == GLFW_KEY_RIGHT_SHIFT) {
if(pressed) {
if(!itemUse_last) {
itemUse_last = true;
Main.player.activateItem();
}
}
else if(itemUse_last) {
itemUse_last = false;
if(key == GLFW_KEY_RIGHT_SHIFT) {
if(pressed) {
if(!itemUse_last) {
itemUse_last = true;
input.itemAction(true);
}
}
if(key == GLFW_KEY_E) {
if(pressed) {
if(!action_last) {
action_last = true;
Main.player.activateTile();
}
}
else if(action_last) {
action_last = false;
}
}
if(key == GLFW_KEY_Q) {
if(pressed) {
if(!itemDrop_last) {
itemDrop_last = true;
Main.player.dropItem();
}
}
else if(itemDrop_last) {
itemDrop_last = false;
}
else if(itemUse_last) {
itemUse_last = false;
}
}
else {
itemUse_last = false;
esc_last = false;
action_last = false;
itemDrop_last = false;
Main.player.MOVE_BACKWARD = false;
Main.player.MOVE_FORWARD = false;
Main.player.MOVE_LEFT = false;
Main.player.MOVE_RIGHT = false;
if(key == GLFW_KEY_E) {
if(pressed) {
if(!action_last) {
action_last = true;
input.activateTile(true);
}
}
else if(action_last) {
action_last = false;
}
}
if(key == GLFW_KEY_Q) {
if(pressed) {
if(!itemDrop_last) {
itemDrop_last = true;
input.itemDrop(true);
}
}
else if(itemDrop_last) {
itemDrop_last = false;
}
}
if(key == GLFW_KEY_ESCAPE) {
if(pressed) {
if(!esc_last) {
esc_last = true;
if(Main.game_paused) {
Main.game_paused = false;
Main.menu = new MenuNone();
}
else {
Main.game_paused = true;
Main.menu = new MenuPause();
}
input.pause(true);
}
}
else if(esc_last) {
@ -147,4 +110,42 @@ public class KeyCallback implements GLFWKeyCallbackI
}
}
@Override
public boolean MainLoopDelay(long millis) {
return millis > 10;
}
@Override
public boolean MainLoopRepeat() {
return true;
}
@Override
public void MainLoopUpdate()
{
Input input = Main.menu.input;
if(moveUp) {
input.move(true, 0);
move_last = true;
}
if(moveDown) {
input.move(true, 180);
move_last = true;
}
if(moveLeft) {
input.camera(true, -1);
}
if(moveRight) {
input.camera(true, 1);
}
if(fireGun) {
input.fire(true);
}
}
}

View File

@ -0,0 +1,14 @@
package shootergame.input.types;
public interface Input
{
public void move(boolean state, double angle);
public void fire(boolean state);
public void activateTile(boolean state);
public void camera(boolean state, double amount);
public void itemAction(boolean state);
public void itemDrop(boolean state);
public void pause(boolean state);
public void hotbarGoto(boolean state, int pos);
public void hotbarShift(boolean state, int amount);
}

View File

@ -0,0 +1,70 @@
package shootergame.input.types;
import shootergame.Main;
import shootergame.menu.MenuGame;
import shootergame.menu.MenuGamePause;
import shootergame.util.math.MathHelpers;
public class InputGame implements Input
{
@Override
public void move(boolean state, double angle)
{
if(state)
{
// Move the player in the left sticks angle
Main.player.moveTowards(angle);
// Set the players moving to true
Main.player.moving = true;
}
else {
Main.player.moving = false;
}
}
@Override
public void fire(boolean state) {
Main.player.fireBullet(0);
}
@Override
public void activateTile(boolean state) {
Main.player.activateTile();
}
@Override
public void camera(boolean state, double amount) {
Main.player.angle += amount;
}
@Override
public void itemAction(boolean state) {
Main.player.activateItem();
}
@Override
public void itemDrop(boolean state) {
Main.player.dropItem();
}
@Override
public void pause(boolean state) {
Main.menu = new MenuGamePause();
Main.game_paused = true;
}
@Override
public void hotbarGoto(boolean state, int pos) {
Main.player.inventory_hand = pos;
}
@Override
public void hotbarShift(boolean state, int amount) {
Main.player.inventory_hand += amount;
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 6);
}
}

View File

@ -0,0 +1,47 @@
package shootergame.input.types;
import shootergame.Main;
import shootergame.menu.MenuGame;
public class InputGamePause implements Input
{
@Override
public void move(boolean state, double angle) {
}
@Override
public void fire(boolean state) {
}
@Override
public void activateTile(boolean state) {
}
@Override
public void camera(boolean state, double amount) {
}
@Override
public void itemAction(boolean state) {
}
@Override
public void itemDrop(boolean state) {
}
@Override
public void pause(boolean state) {
Main.menu = new MenuGame();
Main.game_paused = false;
}
@Override
public void hotbarGoto(boolean state, int pos) {
}
@Override
public void hotbarShift(boolean state, int amount) {
}
}

View File

@ -0,0 +1,62 @@
package shootergame.input.types;
import shootergame.Main;
public class InputMenu implements Input
{
@Override
public void move(boolean state, double angle) {
// TODO
}
@Override
public void fire(boolean state) {
// TODO Auto-generated method stub
}
@Override
public void activateTile(boolean state) {
// TODO Auto-generated method stub
}
@Override
public void camera(boolean state, double amount) {
// TODO Auto-generated method stub
}
@Override
public void itemAction(boolean state) {
// TODO Auto-generated method stub
}
@Override
public void itemDrop(boolean state) {
// TODO Auto-generated method stub
}
@Override
public void pause(boolean state) {
// TODO Auto-generated method stub
}
@Override
public void hotbarGoto(boolean state, int pos) {
// TODO Auto-generated method stub
}
@Override
public void hotbarShift(boolean state, int amount) {
// TODO Auto-generated method stub
}
}

View File

@ -1,8 +1,12 @@
package shootergame.menu;
import shootergame.input.types.Input;
public abstract class Menu
{
public boolean doGameloop = false;
public boolean doGameloop;
public boolean doGameRender;
public Input input;
public abstract void render();
}

View File

@ -0,0 +1,16 @@
package shootergame.menu;
import shootergame.input.types.InputGame;
public class MenuGame extends Menu
{
public MenuGame() {
this.doGameloop = true;
this.doGameRender = true;
this.input = new InputGame();
}
@Override
public void render() {
}
}

View File

@ -1,11 +1,18 @@
package shootergame.menu;
import shootergame.input.types.InputGamePause;
import shootergame.text.Text;
import shootergame.util.gl.GlHelpers;
import shootergame.util.math.vec.Vec2d;
public class MenuPause extends Menu
public class MenuGamePause extends Menu
{
public MenuGamePause() {
this.doGameloop = false;
this.doGameRender = true;
this.input = new InputGamePause();
}
@Override
public void render()
{

View File

@ -0,0 +1,18 @@
package shootergame.menu;
import shootergame.input.types.InputMenu;
public class MenuMain extends Menu
{
public MenuMain() {
this.doGameloop = false;
this.doGameRender = false;
this.input = new InputMenu();
}
@Override
public void render() {
}
}

View File

@ -1,12 +0,0 @@
package shootergame.menu;
public class MenuNone extends Menu
{
public MenuNone() {
this.doGameloop = true;
}
@Override
public void render() {
}
}