X-Git-Url: https://git.ctpug.org.za/?p=koperkapel.git;a=blobdiff_plain;f=koperkapel%2Fhud.py;fp=koperkapel%2Fhud.py;h=8668b6c67ff01f8f5acaf6f911eb19debdd2b544;hp=4bce86c3c332fb6e948171fcd8b5ed0e00c70554;hb=cc4eaf7d2fcb43531d3c6800d1fe481bb8094a51;hpb=57cda86d1aa60e04e3dd7567439cd79cd95f3e1a diff --git a/koperkapel/hud.py b/koperkapel/hud.py index 4bce86c..8668b6c 100644 --- a/koperkapel/hud.py +++ b/koperkapel/hud.py @@ -1,5 +1,7 @@ """ Roach up display. """ +import math +from pygame.surface import Surface from .actors.surf import SurfActor from .serums import default_serums @@ -10,12 +12,35 @@ class HudActor(SurfActor): 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):