diff options
| author | troido <troido@hotmail.com> | 2018-01-17 20:26:16 +0100 |
|---|---|---|
| committer | troido <troido@hotmail.com> | 2018-01-17 20:26:16 +0100 |
| commit | f72c658220a78ec058ceca25118e3e9a499a6c2b (patch) | |
| tree | 2a965a693d95f0ee651732ddc47b7e22bd188030 /asciifarm/client/display/health.py | |
| parent | 0bed6616326348b41c6a907552fff62956ce6f18 (diff) | |
updated maps and refactored client: renamed display parts and removed selector
Diffstat (limited to 'asciifarm/client/display/health.py')
| -rw-r--r-- | asciifarm/client/display/health.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/asciifarm/client/display/health.py b/asciifarm/client/display/health.py new file mode 100644 index 0000000..10d6594 --- /dev/null +++ b/asciifarm/client/display/health.py @@ -0,0 +1,36 @@ + +import curses + +class Health: + + def __init__(self, char=('@',7,0), emptyChar=('-',7,0), colours=False): + self.char = char + self.emptyChar = emptyChar + self.changed = False + self.colours = colours + self.health = 0 + self.maxHealth = 0 + self.widget = None + + def setWidget(self, widget): + self.widget = widget + + def setHealth(self, health, maxHealth): + self.health = health + self.maxHealth = maxHealth + self.widget.change() + + def update(self): + win = self.widget.getWin() + width, height = win.getSize() + width -= 1 + barEnd = round(self.health/self.maxHealth * width) if self.maxHealth > 0 else 0 + win.erase() + win.addLine((0,0),"Health: {}/{}".format(self.health, self.maxHealth)[:width]) + if self.colours: + win.addLine((0, 1), self.char[0]*barEnd, self.char[1:]) + win.addLine((barEnd, 1), self.emptyChar[0]*(width-barEnd), self.emptyChar[1:]) + else: + win.addLine((0, 1), self.char[0]*barEnd) + win.addLine((barEnd, 1), self.emptyChar[0]*(width-barEnd)) + win.noutrefresh() |
