Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 37ead49444e5b03da0eb34916f121f32eb8703b0
parent e6d79416946466810cf9e486920f1d984760cbac
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 13 Jun 2021 04:08:58 -0500

player object now moving

Diffstat:
Msrc/board.py | 7+++++++
Msrc/bus.py | 4++++
Msrc/entity.py | 13+++++++++++++
Msrc/interface.py | 14+++++++++++++-
4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/board.py b/src/board.py @@ -92,6 +92,13 @@ class BoardManager(manager.Manager): return (x, y, gid) return None + def get_board_tile_properties_by_tile_gid(self, gid): + """ + Return the tile properties of the tile associated with + the given gid. + """ + return self.current_board.tmx_data.get_tile_properties_by_gid(gid) + def get_adjacent_tiles_by_tile_pos(self, tile_pos): """ Return cardinal adjacent tiles of the given tile_pos. diff --git a/src/bus.py b/src/bus.py @@ -181,3 +181,7 @@ class ManagerBus(Bus): return self.managers["board_manager"].get_tile_at_position(mousepos) def perform_board_manager_get_tile_at_tile_pos(self, tilepos): return self.managers["board_manager"].get_tile_at_tile_pos(tilepos) + def perform_board_manager_get_board_tile_properties_by_tile_gid(self, gid): + return self.managers["board_manager"].get_board_tile_properties_by_tile_gid(gid) + def perform_entity_manager_move_player(self, tile_offset): + self.managers["entity_manager"].move_player_by_tile_offset(tile_offset) diff --git a/src/entity.py b/src/entity.py @@ -41,6 +41,7 @@ class EntityManager(manager.Manager): """ # First, clear the draw group and other setup self.draw_group.empty() + self.player = None sh = self.system_bus.fetch("sheet_system", "sheets") # Next, get the JSON as a dict @@ -54,6 +55,18 @@ class EntityManager(manager.Manager): self.player.snap_to_tile() self.draw_group.add(self.player) + def move_player_by_tile_offset(self, tile_offset): + """ + Move a player entity by relative tile offset. + """ + if self.player != None: + t = self.bus.perform_board_manager_get_tile_at_tile_pos((self.player.tile_pos[0] + tile_offset[0], self.player.tile_pos[1] + tile_offset[1])) + if t != None: + props = self.bus.perform_board_manager_get_board_tile_properties_by_tile_gid(t[2]) + if props["Passable"]: + self.player.assign_tile((t[0], t[1]), t[2]) + self.player.snap_to_tile() + def update_managed(self, surface = None): """ Update currently managed entities. diff --git a/src/interface.py b/src/interface.py @@ -81,7 +81,19 @@ class GameInterface(subsystem.GameSubsystem): of keys on a mode-by-mode basis. Called during update. """ - pass + if self.game.state_mode == STATE_MODES.Location_Mode: + if self.key_bools[pygame.K_w]: + self.manager_bus.perform_entity_manager_move_player((0, -1)) + self.key_bools[pygame.K_w] = False + elif self.key_bools[pygame.K_s]: + self.manager_bus.perform_entity_manager_move_player((0, 1)) + self.key_bools[pygame.K_s] = False + elif self.key_bools[pygame.K_a]: + self.manager_bus.perform_entity_manager_move_player((-1, 0)) + self.key_bools[pygame.K_a] = False + elif self.key_bools[pygame.K_d]: + self.manager_bus.perform_entity_manager_move_player((1, 0)) + self.key_bools[pygame.K_d] = False def handle_mouse_click(self, event): """