Skip to content

Instantly share code, notes, and snippets.

Last active July 19, 2021 03:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# 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
return surrounding_tiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment