Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Engine;
- import java.nio.DoubleBuffer;
- import org.lwjgl.BufferUtils;
- import org.lwjgl.glfw.GLFW;
- public class IO {
- private long window;
- private boolean[] key = new boolean[GLFW.GLFW_KEY_LAST];
- private boolean[] mouse = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
- public IO(long window)
- {
- this.window = window;
- update();
- }
- public boolean isKeyDown(int key)
- {
- return GLFW.glfwGetKey(this.window, key) == 1;
- }
- public boolean isMouseDown(int mouse)
- {
- return GLFW.glfwGetMouseButton(window, mouse) == 1;
- }
- public boolean isKeyPress(int key)
- {
- return isKeyDown(key) && !this.key[key];
- }
- public boolean isKeyRelease(int key)
- {
- return !isKeyDown(key) && this.key[key];
- }
- public boolean isMoisePress(int mouse)
- {
- return isMouseDown(mouse) && !this.mouse[mouse];
- }
- public boolean isMouseRelease(int mouse)
- {
- return !isMouseDown(mouse) && this.mouse[mouse];
- }
- public double getMouseX()
- {
- DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
- GLFW.glfwGetCursorPos(window, buffer, null);
- return buffer.get(0);
- }
- public double getMouseY()
- {
- DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
- GLFW.glfwGetCursorPos(window, null, buffer);
- return buffer.get(0);
- }
- private void update()
- {
- for(int i = 0; i < GLFW.GLFW_KEY_LAST; i++)
- {
- key[i] = isKeyDown(i);
- }
- for(int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++)
- {
- mouse[i] = isMouseDown(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement