Return to repo list

heart-of-gold

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

commit d2471d1858ef02e7899e977932b122d54246027a
parent 129e2ac273da8bb62cfd8f51bafeb6b263d4e222
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 15 Nov 2020 09:46:37 -0600

Some polish on turn transition and interface behavior

Diffstat:
Msrc/camera.py | 4++--
Msrc/constants.py | 2+-
Msrc/game.py | 4++++
Msrc/interface.py | 14+++++++++++---
Msrc/piece.py | 5++++-
Msrc/turn.py | 18+++++++++++++++---
6 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/camera.py b/src/camera.py @@ -64,9 +64,9 @@ class GameCamera(subsystem.GameSubsystem): changey = rel_offset[1] * speed_multiple self.camera_surface_offset = (self.camera_surface_offset[0] + changex, self.camera_surface_offset[1] + changey) - def lock_to_position(self, position): + def snap_to_position(self, position): """ - Lock the camera to a position, relative + Snap the camera to a position, relative to the screen. The given position should be coordinates on the camera surface, and this method will compute that to produce diff --git a/src/constants.py b/src/constants.py @@ -42,6 +42,6 @@ SCENE_JSON_PATH = os.path.join(JSON_PATH, "scenes") # Enums STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Battle_Mode Still_Scene_Mode') -CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Still_Scene_Normal') +CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Watch_Move Still_Scene_Normal') FACE_DIR = enum.Enum('FACE_DIR', 'U D L R') GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_quit ef_game_switch_mode') diff --git a/src/game.py b/src/game.py @@ -143,6 +143,10 @@ class Game(object): elif self.state_mode == STATE_MODES.Battle_Mode: self.board_manager.update(self.camera.camera_surface) self.piece_manager.update(self.camera.camera_surface) + # NOTE: This must happen here to avoid a very choppy rendering of the + # moving entity caused by the drawing order. + if self.control_mode == CTRL_MODES.Turn_Watch_Move: + self.camera.snap_to_position(self.turn_manager.current_active_piece.rect.center) self.camera.update_camera(self.screen) self.turn_manager.update(self.screen) # Draw to the screen since it manages UI elements elif self.state_mode == STATE_MODES.Still_Scene_Mode: diff --git a/src/interface.py b/src/interface.py @@ -106,9 +106,9 @@ class GameInterface(subsystem.GameSubsystem): if to_path != None: self.bus.perform_set_piece_move_along_tile_path(self.bus.fetch("piece_manager", "selected_piece"), to_path) # TODO: Not like this - self.game.lose_control(len(to_path) * PIECE_MOVE_DELAY, CTRL_MODES.Turn_Normal) + #self.game.lose_control(len(to_path) * PIECE_MOVE_DELAY, CTRL_MODES.Turn_Normal) + self.game.control_mode = CTRL_MODES.Turn_Watch_Move self.bus.perform_load_board_overlay() - self.bus.perform_shift_turns() # Still-scene mode behavior elif self.game.state_mode == STATE_MODES.Still_Scene_Mode: @@ -137,8 +137,16 @@ class GameInterface(subsystem.GameSubsystem): if tilepos != None: self.bus.perform_position_tile_cursor((tilepos[0], tilepos[1])) - if self.game.control_mode == CTRL_MODES.Turn_Normal: + if self.game.control_mode == CTRL_MODES.Turn_Normal or self.game.control_mode == CTRL_MODES.Turn_Select_Move: for r in self.camera.scroll_rects: if self.camera.scroll_rects[r].collidepoint(mouseraw) and pygame.mouse.get_focused(): self.camera.move_offset(r, SCROLL_SPEED) + # Watching a move complete + elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move: + ap = self.bus.fetch("turn_manager", "active_piece") + if not ap.path_moving: + self.bus.perform_shift_turns() + self.game.control_mode = CTRL_MODES.Turn_Normal + + diff --git a/src/piece.py b/src/piece.py @@ -219,6 +219,7 @@ class Piece(entity.Entity): self.current_tile_path_index = 0 self.through_tile_pos = (-1, -1) self.path_moving = False + self.first_path_move_pass = False # Turn order values self.readiness = self.active_stats["INIT"] + self.active_stats["SPD"] @@ -246,6 +247,7 @@ class Piece(entity.Entity): self.current_tile_path = tile_seq self.current_tile_path_index = 0 self.path_moving = True + self.first_path_move_pass = True self.through_tile_pos = self.tile_pos def execute_tile_path_move(self): @@ -268,8 +270,9 @@ class Piece(entity.Entity): elif face_diff == (0, -1): self.facing = FACE_DIR.D - if self.facing != oldface: + if self.facing != oldface or self.first_path_move_pass: self.set_animation(self.manager.bus.fetch("sheet_manager", "animations")[self.sheet.name]["walk_" + self.facing.name], True) + self.first_path_move_pass = False # Setup motion to next tile in the path next_tar = ((self.current_tile_path[self.current_tile_path_index][0] * TILE_WIDTH) + (TILE_WIDTH / 2), diff --git a/src/turn.py b/src/turn.py @@ -32,8 +32,7 @@ class TurnManager(manager.Manager): self.camera = camera self.current_turn = 1 self.current_active_piece = None - #self.turn_projection = [] - self.turn_order = [] + self.turn_projection = [] self.turn_tick = 0 self.in_play_pieces = [] self.turn_depth = 10 @@ -92,6 +91,7 @@ class TurnManager(manager.Manager): # Set the 0th candidate as the current active piece and let it take a turn self.current_active_piece = candidates.pop(0) self.current_active_piece.taking_turn = True + self.camera.snap_to_position(self.current_active_piece.rect.center) # Predict the next turn order self.project_turn_order() @@ -164,9 +164,21 @@ class TurnManager(manager.Manager): self.turn_tray_more_button.set_position((798, self.turn_tray.rect.bottom + 2)) for i in self.turn_icons: if i.rect.collidepoint(pos) and i.clickable: - self.camera.lock_to_position(i.piece.rect.center) + self.camera.snap_to_position(i.piece.rect.center) break + def expose(self): + """ + Expose information about turns. + """ + data = { + "active_piece" : self.current_active_piece, + "turn_number" : self.current_turn, + "in_play_pieces" : self.in_play_pieces, + "turn_projection" : self.turn_projection + } + self.bus.record(self.name, data) + def update_managed(self, surface): """ Update the entities this manager controls.