From f72c658220a78ec058ceca25118e3e9a499a6c2b Mon Sep 17 00:00:00 2001 From: troido Date: Wed, 17 Jan 2018 20:26:16 +0100 Subject: updated maps and refactored client: renamed display parts and removed selector --- asciifarm/client/display/health.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 asciifarm/client/display/health.py (limited to 'asciifarm/client/display/health.py') 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() -- cgit