commit 70c0539b7eefdf13b6d13f0fb9e5d1226a32b88a
parent ca8e8b9b5b59e535f038ffad1e0acf73fdaae609
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Tue, 24 Nov 2020 17:57:20 -0600
Added attack notation texts
Diffstat:
3 files changed, 52 insertions(+), 23 deletions(-)
diff --git a/src/constants.py b/src/constants.py
@@ -83,6 +83,7 @@ STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Battle_Mode Still_Scene_M
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')
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 riposte ignoredef parry block sweep miss onetwo stun')
# Error types
class ManagerBusError(Exception):
diff --git a/src/piece.py b/src/piece.py
@@ -332,12 +332,16 @@ class Piece(entity.Entity):
self.being_damaged = False
self.damage_timer = 0
self.damage_to_receive = 0
- self.damage_number_font = None
- self.damage_number_outline_font = None
+ self.damage_number_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), self.rect.height // 2)
+ self.damage_number_outline_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), (self.rect.height // 2) + 6)
+ self.damage_notation_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), self.rect.height // 3)
self.damage_number_surface = None
self.damage_number_outline = None
self.damage_number_rect = None
self.damage_number_outline_rect = None
+ self.damage_notations = []
+ self.damage_notation_surfaces = []
+ self.damage_notation_rects = []
self.has_moved = False
self.has_acted = False
self.health_bar = None
@@ -418,19 +422,23 @@ class Piece(entity.Entity):
def render_damage_number(self):
"""
- Render the name font image for display.
+ Render the name font image for display. Also
+ renders damage notations.
"""
- self.damage_number_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), self.rect.height // 2)
- self.damage_number_outline_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), (self.rect.height // 2) + 6)
self.damage_number_surface = self.damage_number_font.render(str(self.damage_to_receive), False, (255, 255, 255)).convert()
self.damage_number_outline = self.damage_number_outline_font.render(str(self.damage_to_receive), False, (0, 0, 0)).convert()
self.damage_number_rect = self.damage_number_surface.get_rect()
self.damage_number_outline_rect = self.damage_number_outline.get_rect()
+ for n in self.damage_notations:
+ ns = self.damage_notation_font.render(n, False, (255, 255, 255)).convert()
+ nr = ns.get_rect()
+ self.damage_notation_surfaces.append(ns)
+ self.damage_notation_rects.append(nr)
def set_facing(self, direction):
"""
- Set the direction this piece should face. 'direction' should
- be a valid enum value matching FACE_DIR.
+ Set the direction this piece should face. 'direction'
+ should be a valid enum value matching FACE_DIR.
"""
self.facing = direction
@@ -471,22 +479,46 @@ class Piece(entity.Entity):
self.attack_anim_timer = 90
# Tell the other guy to be damaged
+ notelist = []
+ # Bonus for back attack
+ ba = 0
+ if self.facing == self.attack_target.facing:
+ ba = 0.25
+ notelist.append(ATTACK_NOTATIONS.backattack)
+ # Critical chance calc
+ ca = 1
+ if random.randint(0, 100) in range(0, self.active_stats["LUK"]):
+ ca = 2.5
+ notelist.append(ATTACK_NOTATIONS.critical)
prim = self.active_stats[WEAPON_TYPE_SOURCES[ITEMBASE[self.equipment["weapon"]]["type"]]]
bon = WEAPON_TYPE_SOURCES[ITEMBASE[self.equipment["weapon"]]["type"]]
- raw_dam = max(round((prim * 1.6) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"]) // 2), 0)
+ raw_dam = max(round(((prim + (prim * ba)) * 1.6) + random.randint(-(self.active_stats["LUK"] // 2), self.active_stats["LUK"]) // 2), 0)
if bon != None and raw_dam > 0:
raw_dam += round((self.active_stats[bon] + random.randint(0, self.active_stats["LUK"] // 2)) * 0.2)
elif raw_dam < 0:
raw_dam = 0
- self.attack_target.set_be_damaged_action(raw_dam)
+ self.attack_target.set_be_damaged_action(raw_dam * ca, notelist)
- def set_be_damaged_action(self, raw_damage):
+ def set_be_damaged_action(self, raw_damage, notations):
"""
- Setup the action of being damaged.
+ Setup the action of being damaged. 'notations'
+ is a list of enum vals that are parsed to
+ indicate special things that caused the amount
+ of damage to change. Certain notations can also
+ indicate that the colors of the damage numbers
+ should change.
"""
# TODO: This could eventually take a 'damage_aff' var which determines
# the element of the damage and could be figured into the post-def
# calculations to account for elemental strength/weakness
+
+ # First, notation handling
+ for n in notations:
+ if n == ATTACK_NOTATIONS.backattack:
+ self.damage_notations.append("Back Attack!")
+ elif n == ATTACK_NOTATIONS.critical:
+ self.damage_notations.append("Critical!")
+
if raw_damage <= 0:
self.damage_to_receive = 0
else:
@@ -609,7 +641,6 @@ class Piece(entity.Entity):
if self.damage_timer == 72:
self.set_animation(self.manager.bus.fetch("sheet_manager", "animations")[self.sheet.name]["hurt_" + self.facing.name], True)
elif self.damage_timer == 30:
- # TODO: This is possibly not the best way
self.hp_damage_mod -= self.damage_to_receive
self.modulate_stats()
if self.active_stats["HP"] > 0:
@@ -617,12 +648,13 @@ class Piece(entity.Entity):
else:
self.being_damaged = False
self.damage_to_receive = 0
- self.damage_number_font = None
- self.damage_number_outline_font = None
self.damage_number_surface = None
self.damage_number_outline = None
self.damage_number_rect = None
self.damage_number_outline_rect = None
+ self.damage_notations = []
+ self.damage_notation_surfaces = []
+ self.damage_notation_rects = []
if self.active_stats["HP"] <= 0:
self.manager.kill_piece(self)
self.manager.bus.perform_turn_manager_kill_piece(self)
@@ -686,6 +718,10 @@ class Piece(entity.Entity):
self.damage_number_outline_rect.center = self.damage_number_rect.center
surface.blit(self.damage_number_outline, self.damage_number_outline_rect)
surface.blit(self.damage_number_surface, self.damage_number_rect)
+ for x in range(0, len(self.damage_notation_surfaces)):
+ if self.damage_timer <= 60 - (10 * x):
+ self.damage_notation_rects[x].center = (self.rect.center[0], self.rect.center[1] + ((self.damage_timer // 4) - (10 * x)))
+ surface.blit(self.damage_notation_surfaces[x], self.damage_notation_rects[x])
##########################
# Section 3 - TileCursor #
diff --git a/src/status.py b/src/status.py
@@ -31,7 +31,6 @@ class StatusDisplay(entity.Entity):
self.manager = manager
self.stat_def = stat_def # Consists of a piece's active stats and normal stats, in a dict
self.font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), SCREEN_HEIGHT // 36)
- self.outline_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), SCREEN_HEIGHT // 33)
self.big_font = pygame.font.Font(os.path.join(FONT_PATH, UI_FONT), SCREEN_HEIGHT // 24)
self.affinity_icon = None
self.name_surface = None
@@ -49,9 +48,7 @@ class StatusDisplay(entity.Entity):
self.equipment_surfaces = { i: None for i in self.stat_def["equipment"].keys() }
self.equipment_surface_rects = { i: None for i in self.stat_def["equipment"].keys() }
self.hp_surface = None
- self.hp_outline = None
self.hp_surface_rect = None
- self.hp_outline_rect = None
self.health_bar = None
self.health_bar_rect = None
self.health_bar_fill = None
@@ -150,7 +147,6 @@ class StatusDisplay(entity.Entity):
self.expertise_surface_rects.append(self.expertise_surfaces[x].get_rect())
self.expertise_surface_rects[x].topleft = (self.expertise_surface_position[0] + (102 * x), self.expertise_surface_position[1])
-
for e in self.equipment_surfaces:
if self.stat_def["equipment"][e] != None:
self.equipment_surfaces[e] = self.font.render(ITEMBASE[self.stat_def["equipment"][e]]["name"], False, (0, 0, 0)).convert()
@@ -178,12 +174,9 @@ class StatusDisplay(entity.Entity):
self.health_bar_fill.fill((0, 200, 0))
self.health_bar_rect.topleft = self.health_bar_position
self.health_bar_fill_rect.topleft = (self.health_bar_rect.topleft[0] + 1, self.health_bar_rect.topleft[1] + 1)
- self.hp_surface = self.font.render(str(self.stat_def["active_stats"]["HP"]) + "/" + str(self.stat_def["normal_stats"]["HP"]), False, (0, 0, 0)).convert()
- self.hp_outline = self.outline_font.render(str(self.stat_def["active_stats"]["HP"]) + "/" + str(self.stat_def["normal_stats"]["HP"]), False, (255, 255, 255)).convert()
+ self.hp_surface = self.font.render(str(self.stat_def["active_stats"]["HP"]) + "/" + str(self.stat_def["normal_stats"]["HP"]), False, (255, 255, 255)).convert()
self.hp_surface_rect = self.hp_surface.get_rect()
- self.hp_outline_rect = self.hp_outline.get_rect()
self.hp_surface_rect.center = self.health_bar_rect.center
- self.hp_outline_rect.center = self.hp_surface_rect.center
def update(self, surface = None):
"""
@@ -208,5 +201,4 @@ class StatusDisplay(entity.Entity):
if self.health_bar != None and self.health_bar_fill != None:
surface.blit(self.health_bar, self.health_bar_rect)
surface.blit(self.health_bar_fill, self.health_bar_fill_rect)
- surface.blit(self.hp_outline, self.hp_outline_rect)
surface.blit(self.hp_surface, self.hp_surface_rect)