From 5c5df6e068b2957987cb51b34d6930769424f8ca Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Fri, 29 Mar 2024 00:30:39 +0200 Subject: stats as object --- src/sliceitoff/status/status.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/sliceitoff/status/status.py') diff --git a/src/sliceitoff/status/status.py b/src/sliceitoff/status/status.py index ad3034c..bbe9a03 100644 --- a/src/sliceitoff/status/status.py +++ b/src/sliceitoff/status/status.py @@ -1,23 +1,28 @@ +""" status.status - The statusline bottom of screen showinf all stats """ import pygame -from stats import Stats from text import TextPage class Status(pygame.sprite.Group): - def __init__(self): + """ Statusline bottom of screen """ + def __init__(self, stats = None): super().__init__() + self.stats = stats self.old_srt = None def update(self, **kwargs): """ Rebuilds statusline if needed """ super().update(**kwargs) + percent = int(self.stats.percent) + if percent == 100: + percent = 99 score_str = ( - f"\xee\x12\xef{Stats.level:<2d}" - f"\xec\x03\xef{Stats.lives:<2d}" - f"\xed\x0e\xef{Stats.bonus // 1000:<3d}" - f"\xe9\xfe\xef{99 if Stats.percent == 100 else int(Stats.percent):<3d}" - f"\xea\x0f\xef{Stats.enemies-Stats.field_count:<3d}" - f"{Stats.score:08d}") + f"\xee\x12\xef{self.stats.level:<2d}" + f"\xec\x03\xef{self.stats.lives:<2d}" + f"\xed\x0e\xef{self.stats.bonus // 1000:<3d}" + f"\xe9\xfe\xef{percent:<3d}" + f"\xea\x0f\xef{self.stats.enemies-self.stats.field_count:<3d}" + f"{self.stats.score:08d}") if self.old_srt != score_str: self.empty() self.add( TextPage( -- cgit v1.2.3