Skip to content

Instantly share code, notes, and snippets.

@joooyzee
Last active July 19, 2021 03:37
Show Gist options
  • Save joooyzee/8c1282a1ad9584480f7cbf1ee2df03a4 to your computer and use it in GitHub Desktop.
Save joooyzee/8c1282a1ad9584480f7cbf1ee2df03a4 to your computer and use it in GitHub Desktop.
# given our current location as an (x,y) tuple, return the surrounding tiles as a list
# (i.e. [(x1,y1), (x2,y2),...])
def get_surrounding_tiles(self, location):
# location[0] = x-index; location[1] = y-index
tile_north = (location[0], location[1]+1)
tile_south = (location[0], location[1]-1)
tile_west = (location[0]-1, location[1])
tile_east = (location[0]+1, location[1])
surrounding_tiles = [tile_north, tile_south, tile_west, tile_east]
for tile in surrounding_tiles:
# check if the tile is within the boundaries of the game
if not self.game_state.is_in_bounds(tile):
# remove invalid tiles from our list
surrounding_tiles.remove(tile)
return surrounding_tiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment