commit 075ecfdc2406014e96468fa0e9cfcf4fa9b6e689
parent dacb40e5fd621534994080abd131dfddd1a0437d
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Tue, 24 Nov 2020 13:15:16 -0600
Added HP display in statscreen
Diffstat:
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/src/piece.py b/src/piece.py
@@ -632,11 +632,15 @@ class Piece(entity.Entity):
def modulate_stats(self):
"""
- Calculate each stat mod dict, and apply all
- those mods to the normal_stats to produce the
+ Take each stat mod dict, and apply the sum of
+ all the mods to the normal_stats to produce the
current active_stats. This calculates only
the equip_mod; all other mods are determined
- elsewhere and taken for granted here.
+ elsewhere and taken for granted here. HP is not
+ modifiable by any mod other than hp_damage_mod;
+ no equipment or in-game effects (including rank
+ distribution) can directly raise HP other than
+ leveling up.
"""
self.equip_mod = { i : 0 for i in self.normal_stats }
for e in self.equipment:
diff --git a/src/status.py b/src/status.py
@@ -31,6 +31,8 @@ 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
self.name_surface_rect = None
@@ -44,6 +46,14 @@ class StatusDisplay(entity.Entity):
self.stat_surface_rects = { i: None for i in self.stat_def["normal_stats"].keys() }
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
+ self.health_bar_fill_rect = None
# Surface base positions
# TODO: hardcoded
@@ -54,10 +64,12 @@ class StatusDisplay(entity.Entity):
self.exp_surface_rect_position = (790, 640)
self.stat_surfaces_position = (140, 218)
self.equipment_surfaces_position = (510, 224)
+ self.health_bar_position = (750, 560)
# Load up
self.load_subs()
self.load_text()
+ self.create_health_bar()
def load_subs(self):
"""
@@ -140,6 +152,28 @@ class StatusDisplay(entity.Entity):
self.equipment_surface_rects["acc2"].topleft = (self.equipment_surfaces_position[0], self.equipment_surfaces_position[1] + 84)
self.equipment_surface_rects["acc3"].topleft = (self.equipment_surfaces_position[0], self.equipment_surfaces_position[1] + 112)
+ def create_health_bar(self):
+ """
+ Create a bar indication of current HP.
+ """
+ # TODO: More hardcoding...
+ ahp = self.stat_def["active_stats"]["HP"]
+ nhp = self.stat_def["normal_stats"]["HP"]
+ self.health_bar = pygame.Surface((150, 28)).convert()
+ self.health_bar_rect = self.health_bar.get_rect()
+ self.health_bar_fill = pygame.Surface((round((ahp / nhp) * (self.health_bar_rect.width - 2)), self.health_bar_rect.height - 2)).convert()
+ self.health_bar_fill_rect = self.health_bar_fill.get_rect()
+ self.health_bar.fill((45, 45, 45))
+ 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_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):
"""
Update overwrite to handle drawing subsurfaces.
@@ -157,3 +191,8 @@ class StatusDisplay(entity.Entity):
for e in self.equipment_surfaces:
if self.equipment_surfaces[e] != None:
surface.blit(self.equipment_surfaces[e], self.equipment_surface_rects[e])
+ 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)