Advertisement
Guest User

JavaOpenGL Controlls

a guest
Mar 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public void move() {
  2.  
  3.         if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
  4.             move(-speed, 1);
  5.         }
  6.         if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
  7.             move(speed, 1);
  8.         }
  9.         if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
  10.             move(-speed, 0);
  11.         }
  12.         if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
  13.             move(speed, 0);
  14.         }
  15.         if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
  16.             pos.y += speed;
  17.         }
  18.         if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
  19.            pos.y += -speed;
  20.         }
  21.         if ( Keyboard.isKeyDown(Keyboard.KEY_R)) {
  22.             if ( !R_INCREASED) {
  23.                 speed *= 4f;
  24.                 R_INCREASED = true;
  25.             }
  26.             R_PRESSED = true;
  27.         } else {
  28.             if (R_PRESSED) {
  29.                 speed /= 2f;
  30.                 R_PRESSED   = false;
  31.                 R_INCREASED = false;
  32.             }
  33.         }
  34.         if ( Keyboard.isKeyDown(Keyboard.KEY_E)) {
  35.             pos.x = 0;
  36.             pos.y = 0;
  37.             pos.z = 0;
  38.         }
  39.  
  40.         rotX += -Mouse.getDY() * turnSpeed;
  41.         rotY +=  Mouse.getDX() * turnSpeed;
  42.  
  43.     }
  44.  
  45.     private void move(float amt, int dir) {
  46.         pos.x += amt * (Math.cos(Math.toRadians(rotY + 90 * dir)));
  47.         pos.z += amt * (Math.sin(Math.toRadians(rotY + 90 * dir)));
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement