Return to repo list

heart-of-gold

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

commit 33a4d188fa0c0f5331fa6da82b6beb6496d928f6
parent 33843b4f12a12ff074942dc7ce13bf1f74d5f261
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun, 31 Jan 2021 13:18:23 -0600

added framework for concluding battles

Diffstat:
Mdata/json/scenes/scene1.json | 4++--
Mdata/json/scenes/testdia.json | 2+-
Msrc/constants.py | 2+-
Msrc/turn.py | 41++++++++++++++++++++++++++++++++++++++---
4 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/data/json/scenes/scene1.json b/data/json/scenes/scene1.json @@ -38,8 +38,8 @@ "actor" : [ { "sheet" : "base", "sprite" : [0, 0] }, { "sheet" : "eyes", "sprite" : [1, 2] }, - { "sheet" : "mouth", "sprite" : [0, 0] }, - { "sheet" : "brows", "sprite" : [0, 0] } + { "sheet" : "mouth", "sprite" : [0, 2] }, + { "sheet" : "brows", "sprite" : [0, 1] } ] } ], diff --git a/data/json/scenes/testdia.json b/data/json/scenes/testdia.json @@ -34,7 +34,7 @@ "effects" : [ { "call" : "ef_scene_scroll_camera", - "data" : [0, 3, 20] + "data" : [0, 5, 60] } ] }, diff --git a/src/constants.py b/src/constants.py @@ -89,7 +89,7 @@ OTHER_STATS = ["HP", "EXP", "LVL", "RNK"] # Enums STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Base_Mode Battle_Mode Still_Scene_Mode') -CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Base_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Turn_Watch_Guard Battle_Dialog Battle_Intro Still_Scene_Normal') +CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Base_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Turn_Watch_Guard Battle_Dialog Battle_Intro Battle_Resolve Still_Scene_Normal') FACE_DIR = enum.Enum('FACE_DIR', 'U D L R') GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_dummy ef_game_quit ef_game_switch_mode ef_game_switch_control') SCENE_EFFECTS = enum.Enum('SCENE_EFFECTS', 'ef_scene_dummy ef_scene_delay ef_scene_fade ef_scene_scroll_camera ef_scene_snap_camera ef_scene_spawn_piece') diff --git a/src/turn.py b/src/turn.py @@ -6,6 +6,12 @@ from .constants import * # turn.py # ########### +# TODO: +# 1. The project_turn_order is currently used in two distinct ways: 1) it is called during the refresh_turn_state method which is intended to +# represent a complete refresh of the status of the turns; 2) it is used by itself in kill_piece and possibly in other places. The +# project_turn_order method is one of a few that should probably not be used by itself, but rather only in the context of refreshing the +# TurnManager's turn state. This hints at possible expansion of what 'refreshing the turn state' even means in the future. + # This file contains the following: # 1. The TurnManager class, which handles turn order and displaying turn info in the GUI # 2. Several entity subclasses used by TurnManager to make up the battle UI @@ -34,6 +40,7 @@ class TurnManager(manager.Manager): self.in_play_pieces = [] self.turn_depth = 10 self.board_events = {} + self.winning_team = None # Interval graphics and values self.intro_timer = 0 @@ -129,7 +136,8 @@ class TurnManager(manager.Manager): self.current_active_piece.set_animation(self.current_active_piece.sheet.animations["stand_" + self.current_active_piece.facing.name], True) # Predict the next turn order - self.project_turn_order() + #self.project_turn_order() + self.refresh_turn_state() self.current_active_piece.readiness -= 100 # Set up important UI vals @@ -139,7 +147,7 @@ class TurnManager(manager.Manager): # Snap the camera to the moving piece self.camera.snap_to_position(self.current_active_piece.rect.center) - + # TODO: NOT THIS, OBVIOUSLY if self.current_active_piece.team != TEAMS.Player: self.shift_turns() @@ -239,7 +247,6 @@ class TurnManager(manager.Manager): interface. Also handles double-clicking which has the same effect as double-clicking the piece. """ - # TODO: Should this use the effect interface??? if self.turn_tray_more_button != None: if self.turn_tray_more_button.rect.collidepoint(pos): self.turn_tray_more_button.toggle_more() @@ -290,7 +297,32 @@ class TurnManager(manager.Manager): Refresh the entire state of the turn manager. """ + # TODO: More to be added here. This might be a target for + # expansion in a future refactor. self.project_turn_order() + self.check_battle_resolution() + + def check_battle_resolution(self): + """ + Check if a battle is over. This is checked + in the refresh_turn_state method. + """ + numplayer = 0 + numenemy = 0 + for p in self.in_play_pieces: + if p.team == TEAMS.Player: + numplayer += 1 + elif p.team == TEAMS.Enemy: + numenemy += 1 + + # Lose + if numplayer == 0: + self.game.control_mode = CTRL_MODES.Battle_Resolve + self.winning_team = TEAMS.Player + # Win + elif numenemy == 0: + self.game.control_mode = CTRL_MODES.Battle_Resolve + self.winning_team = TEAMS.Enemy def expose(self): """ @@ -338,6 +370,9 @@ class TurnManager(manager.Manager): self.play_battle_intro() surface.blit(self.intro_left_decal, self.intro_left_decal_topleft) surface.blit(self.intro_right_decal, self.intro_right_decal_topleft) + elif self.game.control_mode == CTRL_MODES.Battle_Resolve: + # TODO: Should be a delay and animation, plus displaying post battle info like loot + self.game.switch_mode(STATE_MODES.Base_Mode, "testbase1") ############################# # Section 2 - Turn Entities #