commit 216770300fef98a8058a2076ba2e67c5f9cbfbd7
parent 3550d3f406da4956ffc3bf64f65a847f7cbb2e61
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Mon, 16 Nov 2020 16:11:36 -0600
Added health bars, and fixed turn order calc error
Diffstat:
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/data/board/testmap1/testmap1.json b/data/board/testmap1/testmap1.json
@@ -32,7 +32,7 @@
},
"active_stats" : {
"LVL" : 1,
- "HP" : 100,
+ "HP" : 80,
"ATK" : 10,
"DEF" : 6,
"SPD" : 9,
@@ -206,7 +206,7 @@
},
"active_stats" : {
"LVL" : 1,
- "HP" : 100,
+ "HP" : 10,
"ATK" : 10,
"DEF" : 6,
"SPD" : 11,
diff --git a/src/piece.py b/src/piece.py
@@ -220,6 +220,11 @@ class Piece(entity.Entity):
self.through_tile_pos = (-1, -1)
self.path_moving = False
self.first_path_move_pass = False
+ self.health_bar = None
+ self.health_bar_fill = None
+ self.health_bar_rect = None
+ self.health_bar_fill_rect = None
+ self.create_health_bar()
# Turn order values
self.readiness = self.active_stats["INIT"] + self.active_stats["SPD"]
@@ -250,6 +255,19 @@ class Piece(entity.Entity):
self.first_path_move_pass = True
self.through_tile_pos = self.tile_pos
+ def create_health_bar(self):
+ """
+ Create a health bar to be displayed along with this piece
+ on the board. The bar is green on red, with the green
+ percentage determined by the remaining HP percentage.
+ """
+ self.health_bar = pygame.Surface((TILE_WIDTH // 2, TILE_HEIGHT // 10))
+ self.health_bar_rect = self.health_bar.get_rect()
+ self.health_bar_fill = pygame.Surface((round((self.active_stats["HP"] / self.normal_stats["HP"]) * (self.health_bar_rect.width - 2)), self.health_bar_rect.height - 2))
+ self.health_bar_fill_rect = self.health_bar_fill.get_rect()
+ self.health_bar.fill((145, 0, 0))
+ self.health_bar_fill.fill((0, 200, 0))
+
def execute_tile_path_move(self):
"""
Execute a move along a tile path.
@@ -299,6 +317,17 @@ class Piece(entity.Entity):
self.set_animation(self.sheet.manager.animations[self.sheet.name]["stand_" + self.facing.name], True)
self.back_to_stand = False
+ def update(self, surface = None):
+ """
+ Overwrite to account for health bars.
+ """
+ super().update(surface)
+ if self.health_bar != None and self.health_bar_fill != None:
+ self.health_bar_rect.center = (self.rect.center[0], self.rect.center[1] + (TILE_HEIGHT // 5))
+ self.health_bar_fill_rect.topleft = (self.health_bar_rect.topleft[0] + 1, self.health_bar_rect.topleft[1] + 1)
+ surface.blit(self.health_bar, self.health_bar_rect)
+ surface.blit(self.health_bar_fill, self.health_bar_fill_rect)
+
##########################
# Section 3 - TileCursor #
##########################
diff --git a/src/turn.py b/src/turn.py
@@ -89,7 +89,7 @@ class TurnManager(manager.Manager):
# Generate a list of next turn candidates. Readiness is increased only here
while len(candidates) == 0:
for p in self.in_play_pieces:
- p.readiness += p.active_stats["INIT"] + min(1, (p.active_stats["SPD"] // 3))
+ p.readiness += p.active_stats["INIT"] + max(1, (p.active_stats["SPD"] // 3))
if p.readiness >= 100:
candidates.append(p)
@@ -141,7 +141,7 @@ class TurnManager(manager.Manager):
# to add new ones
while len(self.turn_projection) < self.turn_depth:
for p in rds:
- rds[p] += p.active_stats["INIT"] + min(1, (p.active_stats["SPD"] // 3))
+ rds[p] += p.active_stats["INIT"] + max(1, (p.active_stats["SPD"] // 3))
if rds[p] >= 100:
next_turn_candidates.append(p)