Guest User

RGC JS new style

a guest
Apr 23rd, 2018
165
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (Mouse.isEventAvailable()) {
  2.     var halfWidth  = window_get_width()  / 2;
  3.     var halfHeight = window_get_height() / 2;
  4.    
  5.     dX = (Mouse.getX() - halfWidth ) * rotSpeed;
  6.     dY = (Mouse.getY() - halfHeight) * rotSpeed;   
  7.    
  8.     if (dX >  10.0) dX =  10.0;
  9.     if (dX < -10.0) dX = -10.0;
  10.     if (dY >  10.0) dY =  10.0;
  11.     if (dY < -10.0) dY = -10.0;
  12.    
  13.     yaw   += dX;
  14.     pitch -= dY;
  15.     if ((pitch > 45.0 ) && (pitch < 180.0)) pitch = 45.0;
  16.     if ((pitch < 315.0) && (pitch > 180.0)) pitch = 315.0;
  17.    
  18.     Mouse.setPosition(halfWidth, halfHeight);
  19. }
  20.  
  21.  
  22. if (Keyboard.isEventAvailable()) {
  23.     if (Keyboard.isKeyHit(VK_RETURN)) print("HELLO!");
  24.    
  25.     if (Keyboard.isKeyPressed(VK_KEY_W)) { // forward
  26.         var rad = deg_to_rad(yaw);
  27.         dX = Math.sin(rad) * moveSpeed;
  28.         dZ = Math.cos(rad) * moveSpeed;
  29.  
  30.         g_PlayerPos.x -= dX;
  31.         g_PlayerPos.z -= dZ;
  32.     }
  33.    
  34.     if (Keyboard.isKeyPressed(VK_KEY_S)) { // backward
  35.         var rad = deg_to_rad(yaw);
  36.         dX = Math.sin(rad) * moveSpeed;
  37.         dZ = Math.cos(rad) * moveSpeed;
  38.            
  39.         g_PlayerPos.x += dX;
  40.         g_PlayerPos.z += dZ;
  41.     }
  42.    
  43.     if (Keyboard.isKeyPressed(VK_KEY_D)) { //right
  44.         var rad = deg_to_rad(yaw - 90.0);
  45.         dX = Math.sin(rad) * moveSpeed;
  46.         dZ = Math.cos(rad) * moveSpeed;
  47.            
  48.         g_PlayerPos.x += dX;
  49.         g_PlayerPos.z += dZ;
  50.     }
  51.    
  52.     if (Keyboard.isKeyPressed(VK_KEY_A)) { //left
  53.         var rad = deg_to_rad(yaw + 90.0);
  54.         dX = Math.sin(rad) * moveSpeed;
  55.         dZ = Math.cos(rad) * moveSpeed;
  56.            
  57.         g_PlayerPos.x += dX;
  58.         g_PlayerPos.z += dZ;
  59.     }
  60. }
RAW Paste Data