summaryrefslogtreecommitdiff
path: root/asciifarm/client/display/health.py
diff options
context:
space:
mode:
authortroido <troido@tilde.town>2018-01-24 13:27:41 +0000
committertroido <troido@tilde.town>2018-01-24 13:27:41 +0000
commitb15f89a3576b98f57ff1ec083e9299c890c1f7fc (patch)
tree3e2772610d8d1a91ff2b8ad17d2cd23ad687a8cd /asciifarm/client/display/health.py
parent50321b57b146944399671b6a8b56c6b769d5ddeb (diff)
parentb1ea1bff79c5e9edf6aedbe8f4183c7e4f92f1e8 (diff)
Merge branch 'master' of https://github.com/jmdejong/rooms
Diffstat (limited to 'asciifarm/client/display/health.py')
-rw-r--r--asciifarm/client/display/health.py36
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()