""" 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):
"smart": (0, 0, 255, 255), # blue
"fast": (0, 255, 0, 255), # green
"strong": (255, 0, 255, 255), # purple
+ "health": (255, 0, 0, 255), # red
"none": (170, 68, 0, 255), # brown
}
def __init__(self, suffix):
self.suffix = suffix
- def assemble_icon(self, name):
+ def assemble_icon(self, name, color=None):
assert name in SERUMS
+ color = color or name
serum_icon = images.load(safepath("serum%s/%s") % (
self.suffix, SERUM_TILENAME_MAP[name],))
frame = serum_icon.copy()
- frame.fill(SERUM_OVERLAY_COLORS[name], None, BLEND_RGBA_MULT)
+ frame.fill(SERUM_OVERLAY_COLORS[color], None, BLEND_RGBA_MULT)
return frame
def assemble(self, name):