Very statis hud.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 22:55:52 +0000 (00:55 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 22:55:52 +0000 (00:55 +0200)
koperkapel/scenes/level.py
koperkapel/serums.py

index 22662a2513017d5fea8c9848cc762f2cfea0fa18..e5de740eac91189febeffd4503ec29193cc3162c 100644 (file)
@@ -8,6 +8,7 @@ from .base import (
     Scene, ChangeSceneEvent, MoveViewportEvent, WorldEvent, defer_to_update)
 from ..constants import TILE_SIZE, WIDTH, HEIGHT
 from ..gamelib.items import clone_old_item, create_new_item
+from ..hud import HudActor
 from ..roaches import build_roach
 from ..vehicles.base import Vehicle
 from ..weapons import weapon_by_name
@@ -25,6 +26,13 @@ class PlayerStats:
         return "<PlayerStats health=%d smart=%d fast=%d strong=%d>" % (
             self.health, self.smart, self.fast, self.strong)
 
+    def __eq__(self, other):
+        if not isinstance(other, PlayerStats):
+            return NotImplemented
+        return all(
+            (self.health == other.health, self.smart == other.smart,
+             self.fast == other.fast, self.strong == other.strong))
+
     def _count_attr(self, attr, roaches):
         attrs = [r[attr] for r in roaches]
         attrs = [a for a in attrs if a]
@@ -119,6 +127,9 @@ class GameLevelScene(BaseLevelScene):
         self._items = self.actors.add_layer("items", level=9)
         self._generators = self.actors.add_layer("enemy generators", level=8)
         self._enemies = self.actors.add_layer("enemies", level=11)
+        self._hud = self.actors.add_layer("hud", level=12)
+        self._hud.add(HudActor(
+            self._stats, anchor=("right", "bottom"), pos=(WIDTH, HEIGHT)))
         self._vehicle = Vehicle.current(world)
         self._mode = 'walk'
         self._angle = 0  # up
@@ -301,6 +312,7 @@ class GameLevelScene(BaseLevelScene):
                 bullet.game_pos[1] * TILE_SIZE + (TILE_SIZE // 2))
         self._check_for_bullet_hits()
         self._update_player_stats(world)
+        self._hud[0].stats = self._stats
         more = self._check_held_keys(dt)
         if more:
             events.extend(more)
index 22391145f2b23843f75bccad381cae6f33fc4d7f..5162180502e36e8c2c126f1da5379f1e5b079049 100644 (file)
@@ -41,6 +41,14 @@ class SerumFactory:
     def __init__(self, suffix):
         self.suffix = suffix
 
+    def assemble_icon(self, name):
+        assert name in SERUMS
+        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)
+        return frame
+
     def assemble(self, name):
         assert name in SERUMS
         puddle = images.load(safepath("serum%s/serum") % (self.suffix,))