Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit b6978031f8ee6baccac7476dbf3f0cbafbbde75d
parent 290b8cb93f25bccbdf6046448653d4ca80957250
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 10 Nov 2020 14:38:27 -0600

Teams now handled correctly in movement calc

Diffstat:
Msrc/board.py | 11++++++-----
Msrc/subsystem.py | 23++++++++++++++++-------
2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/board.py b/src/board.py @@ -116,10 +116,11 @@ class BoardManager(manager.Manager): # TEMP!!!! self.create_move_range(self.bus.fetch_selected_piece()) for t in self.move_targets: - e = entity.Entity(self.bus.fetch_sheet("board_overlays_1"), (1, 0)) - e.set_position((t[0] * self.current_board.tmx_data.tilewidth, t[1] * self.current_board.tmx_data.tileheight)) - e.custom_flags = ("OverlayMove", t) - self.board_overlay.add(e) + if not self.bus.fetch_is_ally_occupied_by_tile_pos(t, self.bus.fetch_selected_piece().team): + e = entity.Entity(self.bus.fetch_sheet("board_overlays_1"), (1, 0)) + e.set_position((t[0] * self.current_board.tmx_data.tilewidth, t[1] * self.current_board.tmx_data.tileheight)) + e.custom_flags = ("OverlayMove", t) + self.board_overlay.add(e) def create_move_range(self, piece): """ @@ -145,7 +146,7 @@ class BoardManager(manager.Manager): for x, y, gid in layer: mx = piece.tile_pos[0] - x my = piece.tile_pos[1] - y - if (abs(mx) + abs(my)) <= movemax and self.current_board.tmx_data.get_tile_properties_by_gid(gid)["Passable"] == 1: + if (abs(mx) + abs(my)) <= movemax and self.current_board.tmx_data.get_tile_properties_by_gid(gid)["Passable"] == 1 and not self.bus.fetch_is_enemy_occupied_by_tile_pos((x, y), piece.team): distances[(x, y)] = movemax + 1 # So we are always greater than the max move # Next, calculate the move from the starting pos to each potential diff --git a/src/subsystem.py b/src/subsystem.py @@ -115,13 +115,14 @@ class GameInterface(GameSubsystem): # Selecting a move for the active piece control elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: - to_path = self.bus.fetch_piece_path_by_previous_moves(self.bus.fetch_selected_piece_tile_pos(), - self.bus.fetch_tile_pos_by_screen_pos(mousepos)) - if to_path != None: - self.bus.perform_set_piece_move_along_tile_path(self.bus.fetch_selected_piece(), to_path) - # TODO: Not like this - self.game.lose_control(len(to_path) * PIECE_MOVE_DELAY, CTRL_MODES.Turn_Normal) - self.bus.perform_load_board_overlay() + if self.bus.fetch_overlay_move_entity_by_screen_pos(mousepos) != None: + targ = self.bus.fetch_tile_pos_by_screen_pos(mousepos) + to_path = self.bus.fetch_piece_path_by_previous_moves(self.bus.fetch_selected_piece_tile_pos(), targ) + if to_path != None: + self.bus.perform_set_piece_move_along_tile_path(self.bus.fetch_selected_piece(), to_path) + # TODO: Not like this + self.game.lose_control(len(to_path) * PIECE_MOVE_DELAY, CTRL_MODES.Turn_Normal) + self.bus.perform_load_board_overlay() # Still-scene mode behavior elif self.game.state_mode == STATE_MODES.Still_Scene_Mode: @@ -191,6 +192,12 @@ class ManagerBus(GameSubsystem): return self.game.piece_manager.selected_piece def fetch_selected_piece_tile_pos(self): return self.game.piece_manager.selected_piece.tile_pos + def fetch_is_enemy_occupied_by_tile_pos(self, tile_pos, team): + o = self.game.piece_manager.get_piece_by_tile(tile_pos) + return not (o == None or o.team == team) + def fetch_is_ally_occupied_by_tile_pos(self, tile_pos, team): + o = self.game.piece_manager.get_piece_by_tile(tile_pos) + return not (o == None or o.team != team) def fetch_tile_by_screen_pos(self, position): return self.game.board_manager.get_tile_at_position(position) def fetch_tile_by_tile_pos(self, tile_pos): @@ -199,6 +206,8 @@ class ManagerBus(GameSubsystem): return self.game.board_manager.get_tile_pos_at_position(position) def fetch_piece_path_by_previous_moves(self, start_tile, target_tile): return self.game.board_manager.get_path_by_previous_moves(start_tile, target_tile) + def fetch_overlay_move_entity_by_screen_pos(self, position): + return self.game.board_manager.get_overlay_move_entity_at_pos(position) def fetch_current_board_width(self): if self.game.board_manager.current_board != None: return self.game.board_manager.current_board.tmx_data.width