jeu-de-combat/src/engine/input/KeyboardInput.java
2021-06-21 15:22:06 +02:00

59 lines
2.0 KiB
Java

package engine.input;
import engine.Engine;
import engine.math.Vector3f;
import engine.object.ObjectGl;
import gameplay.match.match;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWKeyCallback;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
public class KeyboardInput extends GLFWKeyCallback {
public static boolean[] keys = new boolean[65536];
@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
keys[key] = action != GLFW.GLFW_RELEASE;
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
else if(key == GLFW_KEY_SPACE && action == GLFW_PRESS) //Switch to wireframe
if (glGetInteger(GL_POLYGON_MODE) == GL_FILL) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
else if(key == GLFW_KEY_K && action == GLFW_PRESS){
match.showP1Hitbox = !match.showP1Hitbox;
match.showP2Hitbox = !match.showP2Hitbox;
}
}
public static boolean isKeyDown(int keyCode) {
return glfwGetKey(Engine.getWindow(), keyCode) == 1;
}
public static void keyboardInput(ObjectGl token, int speed) {
boolean keyPressed = false;
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_S)) {
token.setTextureWrap(161,260,56,59);
keyPressed = true;
} else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) {
keyPressed = true;
}
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) {
token.translate(new Vector3f (speed * -1.0f, 0.0f, 0.0f));
token.setTextureWrap(121,0,57,82);
keyPressed = true;
}
else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_D)) {
token.translate(new Vector3f (speed * 1.0f, 0.0f, 0.0f));
token.setTextureWrap(178,0,62,82);
keyPressed = true;
}
if (!keyPressed) token.setTextureWrap(58,0,62,82);
}
}