Return to repo list

heart-of-gold

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

commit 648d7c11b35c470799957f2f11bbe81bbc9ee618
parent 773fc528fa5c5458f4baf6c58aaa1bbacc9b151d
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 18 Sep 2020 20:50:17 -0500

Changed by-tile ent selection to exclude tile_cursor

Diffstat:
Msrc/game.py | 15++++++++++++---
Msrc/vgo.py | 33+++++++++++++++++++++++----------
2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/src/game.py b/src/game.py @@ -145,6 +145,8 @@ class GameInterface(GameSubsystem): self.handle_key_press(event) elif event.type == pygame.KEYUP: self.handle_key_release(event) + elif event.type == pygame.MOUSEBUTTONDOWN: + self.handle_mouse_click(event) elif event.type == pygame.QUIT: self.game.quit_game() @@ -160,13 +162,20 @@ class GameInterface(GameSubsystem): """ pass - def handle_mouse_click(self, mousebutton): + def handle_mouse_click(self, event): """ React to a mousebutton being clicked. """ - pass + 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 + if self.game.entity_manager.selected_entities != None: + for e in self.game.entity_manager.selected_entities: + if e.name != "Tile_Cursor": + print(e.name) - def handle_mouse_release(self, mousebutton): + def handle_mouse_release(self, event): """ React to a mousebutton being released. """ diff --git a/src/vgo.py b/src/vgo.py @@ -194,6 +194,7 @@ class EntityManager(manager.Manager): # Entity values self.loaded_entities = pygame.sprite.LayeredDirty() self.tile_cursor = None + self.selected_entities = None self.total_entities = 0 # total number of unique entities loaded def add_entity(self, entity): @@ -237,29 +238,41 @@ class EntityManager(manager.Manager): # stuff that doesn't have to be here. It just helps with # debug. The only important things are the two calls to # self.tile_cursor methods. - ot = (self.tile_cursor.tile_pos, self.tile_cursor.tile_gid) + #ot = (self.tile_cursor.tile_pos, self.tile_cursor.tile_gid) self.tile_cursor.assign_tile(tile_def) self.tile_cursor.snap_to_tile() - if ot != (self.tile_cursor.tile_pos, self.tile_cursor.tile_gid): - e = self.get_entities_by_tile(tile_def) - print(self.game.board_manager.get_tile_at_tile_pos(self.tile_cursor.tile_pos)) - if e != []: - for en in e: - if en.unit != None: - print("Occupied by: " + en.name + "(" + str(en.ent_id) + ")") - print("HP: " + str(en.unit.active_stats["HP"])) + #if ot != (self.tile_cursor.tile_pos, self.tile_cursor.tile_gid): + # e = self.get_entities_by_tile(tile_def) + # print(self.game.board_manager.get_tile_at_tile_pos(self.tile_cursor.tile_pos)) + # if e != []: + # for en in e: + # if en.unit != None: + # print("Occupied by: " + en.name + "(" + str(en.ent_id) + ")") + # print("HP: " + str(en.unit.active_stats["HP"])) def get_entities_by_tile(self, tile_def): """ Find if there are any loaded entities at the provided tile definition. """ + # TODO: Should not just check for TileCursor name, should be something more concrete found_ents = [] for e in self.loaded_entities: - if e.tile_pos == (tile_def[0], tile_def[1]): + if e.tile_pos == (tile_def[0], tile_def[1]) and e.name != "Tile_Cursor": found_ents.append(e) return found_ents + def select_entities_with_tile_cursor(self, tile_def): + """ + Select the current entity under the tile cursor by way + of the tile_def. + """ + e = self.get_entities_by_tile(tile_def) + if e != []: + self.selected_entities = e + else: + self.selected_entities = None + def update_entities(self, surface = None): """ Update all loaded entities.