Return to repo list

heart-of-gold

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

commit db274a2b0d909e89599feb1f8768ae06df35f422
parent 1e364ab27f62898deb69ee8f7b1a56f6c5b2d13d
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 20 Sep 2020 12:44:38 -0500

Much better implementation of move range display

Diffstat:
Msrc/board.py | 37+++++++++++++++++++++----------------
Msrc/game.py | 7-------
Msrc/vgo.py | 8+++++---
3 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/board.py b/src/board.py @@ -40,8 +40,8 @@ class BoardManager(manager.Manager): def load_overlay(self): """ - Derive an overlay from available loaded board. Called in - init and should not be referenced directly. + Derive an overlay from available loaded board. Calling + this has the effect of refreshing the overlay. """ self.board_overlay = pygame.sprite.LayeredDirty() for layer in self.current_board.tmx_data.visible_layers: @@ -86,20 +86,25 @@ class BoardManager(manager.Manager): return (x, y, gid) return None - def display_selected_unit_move_range(self): - """ - Display the move range of the selected unit. - """ - bt = self.game.entity_manager.selected_entities[0].tile_pos - mv = self.game.entity_manager.selected_entities[0].unit.active_stats["MOVE"] - for layer in self.current_board.tmx_data.visible_layers: - if isinstance(layer, pytmx.TiledTileLayer): - for x, y, gid in layer: - if abs(x - bt[0]) <= mv and abs(y - bt[1]) <= mv: - v = vgo.VisibleGameObject(self.game.sheet_manager.loaded_sheets["board_overlays_1"]) - v.set_position((x * self.current_board.tmx_data.tilewidth, y * self.current_board.tmx_data.tileheight)) - v.set_sprite((1, 0)) - self.board_overlay.add(v) + def display_entity_move_range(self, ent = None): + """ + Display the move range of the given entity, or undisplay + move range from overlay if no entity is passed. + """ + if ent != None: + bt = ent.tile_pos + mv = ent.unit.active_stats["MOVE"] + for layer in self.current_board.tmx_data.visible_layers: + if isinstance(layer, pytmx.TiledTileLayer): + for x, y, gid in layer: + if abs(x - bt[0]) <= mv and abs(y - bt[1]) <= mv: + v = vgo.VisibleGameObject(self.game.sheet_manager.loaded_sheets["board_overlays_1"]) + v.set_position((x * self.current_board.tmx_data.tilewidth, y * self.current_board.tmx_data.tileheight)) + v.set_sprite((1, 0)) + self.board_overlay.add(v) + else: + #TODO: This should probably do more than just refresh overlay load + self.load_overlay() def update_board(self, surface = None): """ diff --git a/src/game.py b/src/game.py @@ -169,13 +169,6 @@ class GameInterface(GameSubsystem): if event.button == 1: t = self.game.board_manager.get_tile_at_position(pygame.mouse.get_pos()) self.game.entity_manager.select_entities_with_tile_cursor(t) - # TODO: This is just debug code below - # TODO: displaying move range needs to be undone if clicking no unit - if self.game.entity_manager.selected_entities != None: - self.game.board_manager.display_selected_unit_move_range() - for e in self.game.entity_manager.selected_entities: - if e.name != "Tile_Cursor": - print(e.name) def handle_mouse_release(self, event): """ diff --git a/src/vgo.py b/src/vgo.py @@ -194,7 +194,7 @@ class EntityManager(manager.Manager): # Entity values self.loaded_entities = pygame.sprite.LayeredDirty() self.tile_cursor = None - self.selected_entities = None + self.selected_entity = None self.total_entities = 0 # total number of unique entities loaded def add_entity(self, entity): @@ -269,9 +269,11 @@ class EntityManager(manager.Manager): """ e = self.get_entities_by_tile(tile_def) if e != []: - self.selected_entities = e + self.selected_entity = e[0] # Select only the topmost ent on this tile + self.game.board_manager.display_entity_move_range(self.selected_entity) else: - self.selected_entities = None + self.selected_entity = None + self.game.board_manager.display_entity_move_range(self.selected_entity) def update_entities(self, surface = None): """