Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package Engine;
  2.  
  3. import java.nio.DoubleBuffer;
  4.  
  5. import org.lwjgl.BufferUtils;
  6. import org.lwjgl.glfw.GLFW;
  7.  
  8. public class IO {
  9.    
  10.     private long window;
  11.     private boolean[] key = new boolean[GLFW.GLFW_KEY_LAST];
  12.     private boolean[] mouse = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
  13.    
  14.     public IO(long window)
  15.     {
  16.         this.window = window;
  17.        
  18.         update();
  19.     }
  20.    
  21.     public boolean isKeyDown(int key)
  22.     {
  23.         return GLFW.glfwGetKey(this.window, key) == 1;
  24.     }
  25.    
  26.     public boolean isMouseDown(int mouse)
  27.     {
  28.         return GLFW.glfwGetMouseButton(window, mouse) == 1;
  29.     }
  30.    
  31.     public boolean isKeyPress(int key)
  32.     {
  33.         return isKeyDown(key) && !this.key[key];
  34.     }
  35.  
  36.     public boolean isKeyRelease(int key)
  37.     {
  38.         return !isKeyDown(key) && this.key[key];
  39.     }
  40.    
  41.     public boolean isMoisePress(int mouse)
  42.     {
  43.         return isMouseDown(mouse) && !this.mouse[mouse];
  44.     }
  45.    
  46.     public boolean isMouseRelease(int mouse)
  47.     {
  48.         return !isMouseDown(mouse) && this.mouse[mouse];
  49.     }
  50.    
  51.     public double getMouseX()
  52.     {
  53.         DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
  54.         GLFW.glfwGetCursorPos(window, buffer, null);
  55.         return buffer.get(0);
  56.     }
  57.    
  58.     public double getMouseY()
  59.     {
  60.         DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
  61.         GLFW.glfwGetCursorPos(window, null, buffer);
  62.         return buffer.get(0);
  63.     }
  64.    
  65.     private void update()
  66.     {
  67.         for(int i = 0; i < GLFW.GLFW_KEY_LAST; i++)
  68.         {
  69.             key[i] = isKeyDown(i);
  70.         }
  71.        
  72.         for(int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++)
  73.         {
  74.             mouse[i] = isMouseDown(i);
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement