Advertisement
heroofhyla

XYCoords examples

Apr 15th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. //from class Entity
  2. //position is an XYCoord in Entity
  3. public XYCoords nextCoord(int direction){
  4.     int nextX = position.x();
  5.     int nextY = position.y();
  6.     if (direction == 0 || direction == 1 || direction == 7){
  7.         nextX += 2;
  8.     }
  9.     if (direction == 3 || direction == 4 || direction == 5){
  10.         nextX -= 2;
  11.     }
  12.     if (direction == 1 || direction == 2 || direction == 3){
  13.         nextY -= 2;
  14.     }
  15.     if (direction == 5 || direction == 6 || direction == 7){
  16.         nextY += 2;
  17.     }
  18.    
  19.     return new XYCoords(nextX, nextY);
  20. }
  21.  
  22.  
  23. //from enemy pathing logic (simplified version)
  24. if (lineOfSight(game.knight.position)){
  25.     if (validMove(nextCoord(directionToTile(game.knight.position)))){
  26.         direction = directionToTile(game.knight.position);
  27.     }
  28. }
  29. position = nextCoord(direction);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement