""" Roach up display. """
+import math
+from pygame.surface import Surface
from .actors.surf import SurfActor
from .serums import default_serums
self.stats = stats
super().__init__(surf=self._surf, **kw)
+ def _build_bar(self, value, *args, **kw):
+ icon = default_serums.assemble_icon(*args, **kw)
+ rect = icon.get_rect()
+ value = math.ceil(value)
+ surf = Surface((rect.w, rect.h * value)).convert_alpha()
+ surf.fill((255, 255, 255, 0))
+ x, y = 0, (surf.get_rect().h - rect.h)
+ for i in range(value):
+ surf.blit(icon, (x, y))
+ y -= rect.h / 4
+ return surf
+
def _rebuild_hud_surf(self):
- smart = default_serums.assemble_icon("smart")
- fast = default_serums.assemble_icon("fast")
- strong = default_serums.assemble_icon("strong")
- health = default_serums.assemble_icon("strong")
- return smart
+ stats = self._stats
+ bars = [
+ self._build_bar(stats.smart, "smart"),
+ self._build_bar(stats.fast, "fast"),
+ self._build_bar(stats.strong, "strong"),
+ self._build_bar(stats.health / 5, "strong", color="health"),
+ ]
+ rects = [b.get_rect() for b in bars]
+ h, w = max(r.h for r in rects), sum(r.w for r in rects)
+ x = (w - rects[0].w) / 2
+ surf = Surface((w, h)).convert_alpha()
+ surf.fill((255, 255, 255, 0))
+ for i, bar in enumerate(bars):
+ surf.blit(bar, (x, h - rects[i].h))
+ x += rects[i].w / 2
+ return surf
@property
def stats(self):