X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new%2Fplomrogue%2Fmapping.py;h=64dad7c8a5ac0490c1f440dc3909876de4d5aa36;hb=65e83c99b95a619afc79e8984e6f5027bc7aac1b;hp=aa76b61d1123dee7c7625f03302a8e16bc399300;hpb=e530d9faf68b4057322f5cc61aa0e3b76f8db3f6;p=plomrogue2-experiments diff --git a/new/plomrogue/mapping.py b/new/plomrogue/mapping.py index aa76b61..64dad7c 100644 --- a/new/plomrogue/mapping.py +++ b/new/plomrogue/mapping.py @@ -43,7 +43,7 @@ class Map(MapBase): """Iterate over YX position coordinates.""" for y in range(self.size[0]): for x in range(self.size[1]): - yield [y, x] + yield (y, x) def lines(self): width = self.size[1] @@ -62,6 +62,7 @@ class Map(MapBase): def get_neighbors(self, pos): neighbors = {} + pos = tuple(pos) if not hasattr(self, 'neighbors_to'): self.neighbors_to = {} if pos in self.neighbors_to: @@ -95,20 +96,20 @@ class Map(MapBase): class MapWithLeftRightMoves(Map): def move_LEFT(self, start_pos): - return [start_pos[0], start_pos[1] - 1] + return (start_pos[0], start_pos[1] - 1) def move_RIGHT(self, start_pos): - return [start_pos[0], start_pos[1] + 1] + return (start_pos[0], start_pos[1] + 1) class MapSquare(MapWithLeftRightMoves): def move_UP(self, start_pos): - return [start_pos[0] - 1, start_pos[1]] + return (start_pos[0] - 1, start_pos[1]) def move_DOWN(self, start_pos): - return [start_pos[0] + 1, start_pos[1]] + return (start_pos[0] + 1, start_pos[1]) @@ -120,27 +121,27 @@ class MapHex(MapWithLeftRightMoves): def move_UPLEFT(self, start_pos): if start_pos[0] % 2 == 1: - return [start_pos[0] - 1, start_pos[1] - 1] + return (start_pos[0] - 1, start_pos[1] - 1) else: - return [start_pos[0] - 1, start_pos[1]] + return (start_pos[0] - 1, start_pos[1]) def move_UPRIGHT(self, start_pos): if start_pos[0] % 2 == 1: - return [start_pos[0] - 1, start_pos[1]] + return (start_pos[0] - 1, start_pos[1]) else: - return [start_pos[0] - 1, start_pos[1] + 1] + return (start_pos[0] - 1, start_pos[1] + 1) def move_DOWNLEFT(self, start_pos): if start_pos[0] % 2 == 1: - return [start_pos[0] + 1, start_pos[1] - 1] + return (start_pos[0] + 1, start_pos[1] - 1) else: - return [start_pos[0] + 1, start_pos[1]] + return (start_pos[0] + 1, start_pos[1]) def move_DOWNRIGHT(self, start_pos): if start_pos[0] % 2 == 1: - return [start_pos[0] + 1, start_pos[1]] + return (start_pos[0] + 1, start_pos[1]) else: - return [start_pos[0] + 1, start_pos[1] + 1] + return (start_pos[0] + 1, start_pos[1] + 1) @@ -224,11 +225,11 @@ class FovMap: def basic_circle_out_move(self, pos, direction): """Move position pos into direction. Return whether still in map.""" mover = getattr(self, 'move_' + direction) - pos[:] = mover(pos) + pos = mover(pos) if pos[0] < 0 or pos[1] < 0 or \ pos[0] >= self.size[0] or pos[1] >= self.size[1]: - return False - return True + return pos, False + return pos, True def circle_out(self, yx, f): # Optimization potential: Precalculate movement positions. (How to check @@ -245,11 +246,12 @@ class FovMap: #print('DEBUG CIRCLE_OUT', yx) while circle_in_map: circle_in_map = False - self.basic_circle_out_move(yx, 'RIGHT') + yx, _ = self.basic_circle_out_move(yx, 'RIGHT') for dir_i in range(len(self.circle_out_directions)): for dir_progress in range(distance): direction = self.circle_out_directions[dir_i] - if self.circle_out_move(yx, direction): + yx, test = self.circle_out_move(yx, direction) + if test: f(yx, distance, dir_i, dir_progress) circle_in_map = True distance += 1