commit 4a09ddf982532784490df20cf4009f1a70d4b5e3
parent 5952fae55c93a180c424151d523cc33a1899940d
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Tue, 22 Dec 2020 14:36:29 -0600
Added guard button function
Diffstat:
5 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/src/bus.py b/src/bus.py
@@ -115,6 +115,8 @@ class ManagerBus(subsystem.GameSubsystem):
self.game.piece_manager.set_piece_move_to_tile_path(piece, path)
def perform_execute_attack(self, attacker, target):
self.game.piece_manager.execute_attack(attacker, target)
+ def perform_execute_guard(self, piece):
+ self.game.piece_manager.execute_guard(piece)
def perform_piece_manager_kill_piece(self, piece):
self.game.piece_manager.kill_piece(piece)
def perform_continue_current_scene_script(self):
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 Battle_Mode Still_Scene_Mode')
-CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Still_Scene_Normal')
+CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal Turn_Normal Turn_Select_Move Turn_Select_Attack Turn_Watch_Move Turn_Watch_Attack Turn_Display_Stats Turn_Watch_Guard 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')
ATTACK_NOTATIONS = enum.Enum('ATTACK_NOTATIONS', 'backattack critical counter opposite weakness resist riposte ignoredef parry block sweep miss onetwo stun')
diff --git a/src/interface.py b/src/interface.py
@@ -196,7 +196,6 @@ class GameInterface(subsystem.GameSubsystem):
if self.drag_piece:
diff = (self.drag_from_pos[0] - mouseraw[0], self.drag_from_pos[1] - mouseraw[1])
if diff != (0, 0):
- ap = self.bus.fetch("turn_manager", "active_piece")
if abs(diff[0]) > abs(diff[1]):
if diff[0] >= 0:
ap.facing = FACE_DIR.L
@@ -225,6 +224,13 @@ class GameInterface(subsystem.GameSubsystem):
if not ap.path_moving:
self.game.control_mode = CTRL_MODES.Turn_Normal
+ # Watchin the brief guard anim
+ elif self.game.control_mode == CTRL_MODES.Turn_Watch_Guard:
+ ap = self.bus.fetch("turn_manager", "active_piece")
+ if ap.has_guarded:
+ self.game.control_mode = CTRL_MODES.Turn_Normal
+ self.bus.perform_shift_turns()
+
# Watching an attack complete
elif self.game.control_mode == CTRL_MODES.Turn_Watch_Attack:
ap = self.bus.fetch("turn_manager", "active_piece")
diff --git a/src/piece.py b/src/piece.py
@@ -213,6 +213,13 @@ class PieceManager(manager.Manager):
if attacker in self.pieces and target in self.pieces:
attacker.set_attack_action(target)
+ def execute_guard(self, piece):
+ """
+ Execute a guard action by piece.
+ """
+ if piece in self.pieces and not piece.guarding:
+ piece.set_guard_action()
+
def kill_piece(self, piece):
"""
Remove a piece from everything.
@@ -344,6 +351,9 @@ class Piece(entity.Entity):
self.damage_notation_rects = []
self.has_moved = False
self.has_acted = False
+ self.has_guarded = False
+ self.guarding = False
+ self.show_guard_timer = 20
self.health_bar = None
self.health_bar_fill = None
self.health_bar_rect = None
@@ -572,6 +582,13 @@ class Piece(entity.Entity):
self.dodging = True
self.render_damage_number(hit)
+ def set_guard_action(self):
+ """
+ Setup for the guarding action.
+ """
+ self.guarding = True
+ self.set_animation(self.sheet.animations["block_" + self.facing.name], True)
+
def get_full_stat_def(self):
"""
Returns a stat_def dict organized for status
@@ -663,6 +680,18 @@ class Piece(entity.Entity):
self.back_to_stand = True
self.has_moved = True
+ def execute_guard_action(self):
+ """
+ Execute a guard action and pass turn.
+ """
+ if self.guarding and not self.has_guarded:
+ if self.show_guard_timer > 0:
+ self.show_guard_timer -= 1
+ else:
+ self.has_acted = True
+ self.has_guarded = True
+ self.show_guard_timer = 20
+
def execute_attack_action(self):
"""
Execute an attack action against a preset target.
@@ -751,6 +780,7 @@ class Piece(entity.Entity):
self.execute_tile_path_move()
self.execute_attack_action()
self.execute_be_damaged()
+ self.execute_guard_action()
self.modulate_stats()
# TODO: Something else should be done so that this doesn't overwrite other
# legit non-walking, non-standing anims. THIS MAY NOT BE THE BEST.
diff --git a/src/turn.py b/src/turn.py
@@ -100,6 +100,8 @@ class TurnManager(manager.Manager):
self.current_active_piece.taking_turn = True
self.current_active_piece.has_moved = False
self.current_active_piece.has_acted = False
+ self.current_active_piece.has_guarded = False
+ self.current_active_piece.guarding = False
self.camera.snap_to_position(self.current_active_piece.rect.center)
# Predict the next turn order
@@ -214,6 +216,9 @@ class TurnManager(manager.Manager):
self.bus.perform_display_attack_range_of_piece(self.current_active_piece)
self.camera.snap_to_position(self.current_active_piece.rect.center)
self.game.control_mode = CTRL_MODES.Turn_Select_Attack
+ elif self.action_buttons[4].rect.collidepoint(pos) and self.action_buttons[4].clickable:
+ self.bus.perform_execute_guard(self.current_active_piece)
+ self.game.control_mode = CTRL_MODES.Turn_Watch_Guard
elif self.action_buttons[6].rect.collidepoint(pos) and self.action_buttons[6].clickable:
self.shift_turns()
@@ -265,7 +270,7 @@ class TurnManager(manager.Manager):
self.turn_icons[j].clickable = True
for b in self.action_buttons:
b.update(surface)
- elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move:
+ elif self.game.control_mode in (CTRL_MODES.Turn_Watch_Move, CTRL_MODES.Turn_Watch_Guard):
if self.action_buttons[0].clickable:
self.action_buttons[0].toggle_activation()
elif self.game.control_mode == CTRL_MODES.Turn_Watch_Attack: