Advertisement
Guest User

Untitled

a guest
Jan 25th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. float prevX = X;
  2.         float prevZ = Z;
  3.         boolean isMoved = vInput != 0;
  4.        
  5.         X -= -Math.sin(rad) * (vInput * MOVEMENT_SPEED);
  6.         Z -= Math.cos(rad) * (vInput * MOVEMENT_SPEED);
  7.        
  8.         if(collideTest())
  9.         {
  10.             X = prevX;
  11.             Z = prevZ;
  12.            
  13.             isMoved = false;
  14.         }
  15.  
  16. public boolean collideTest(int x, int y, int size)
  17.     {
  18.         final int collideMargin = 64;
  19.        
  20.         for(int i = 0; i < worldHeight; i++)
  21.         {
  22.             for(int j = 0; j < worldWidth; j++)
  23.             {
  24.                 if(tiles[i * worldWidth + j] != 0 &&
  25.                         aabbTest(x, y, (j * CUBE_SIZE) - CUBE_SIZE, i * CUBE_SIZE, CUBE_SIZE + collideMargin, CUBE_SIZE + collideMargin))
  26.                 {
  27.                     return true;
  28.                 }
  29.             }
  30.         }
  31.        
  32.         return false;
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement