Soldtodie 76 Share Posted June 25, 2017 public enum Rotation { NORTH(1024, new Tile(0, 1)), EAST(1536, new Tile(1, 0)), SOUTH(0, new Tile(0, -1)), WEST(512, new Tile(-1, 0)), NORTH_EAST(1280, new Tile(1, 1)), SOUTH_EAST(1792, new Tile(1, -1)), SOUTH_WEST(256, new Tile(-1, -1)), NORTH_WEST(768, new Tile(-1, 1)); private int rotation; private Tile direction; Rotation(int rotation, Tile direction) { this.rotation = rotation; this.direction = direction; } public int getRotation() { return this.rotation; } public Tile getDirection() { return this.direction; } } public Tile getTilePlayerIsFacing(Player player, boolean onlyCardinal) { if(player != null) { Rotation rot = getRotation(player.getRotation(), onlyCardinal ? 4 : 8); if(rot != null) { return player.getTile().translate(rot.getDirection()); } } return null; } public Rotation getRotation(int rotation, int loop) { for(int i = 0; i < loop; i++) { if(Math.abs(Rotation.values()[i].getRotation() - rotation) <= 128) { return Rotation.values()[i]; } } return null; } public boolean isFacing(Player player, Tile pos, boolean onlyCardinal) { if (player != null && pos != null) { Rotation rot = getRotation(player.getRotation(), onlyCardinal ? 4 : 8); if (rot != null) { if (player.getTile().translate(rot.getDirection()).equals(pos)) { return true; } } } return false; } Link to comment Share on other sites More sharing options...
RetroBot 35 Share Posted August 10, 2017 Thanks for this snippet! I needed something just like this. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.