aboutsummaryrefslogtreecommitdiff
path: root/internal/game/ui_combat.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-21 02:26:57 -0400
committerhistoria <[not public]>2026-06-21 02:26:57 -0400
commite4bc2de6e6aa507044a6a75b4c1954974539a857 (patch)
tree608f22548bf2b6a1a4b02bedad05ec7f3a3aa3f2 /internal/game/ui_combat.go
parentc36c1dc0c65e65b4d6ee53df6bbcc3a860eb6e4b (diff)
downloadthehouseoficarus-e4bc2de6e6aa507044a6a75b4c1954974539a857.tar.gz
feat: combat health bar. color improvements.
Diffstat (limited to 'internal/game/ui_combat.go')
-rw-r--r--internal/game/ui_combat.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/game/ui_combat.go b/internal/game/ui_combat.go
new file mode 100644
index 0000000..56de7e8
--- /dev/null
+++ b/internal/game/ui_combat.go
@@ -0,0 +1,59 @@
+package game
+
+import (
+ "math"
+ "strings"
+
+ "thehouseoficarus/internal/color"
+ "thehouseoficarus/internal/net"
+)
+
+func (g *Game) hpBar(sess *net.Session, current, max int) string {
+ if max <= 0 {
+ max = 1
+ }
+ if current < 0 {
+ current = 0
+ }
+ if current > max {
+ current = max
+ }
+
+ pct := float64(current) / float64(max) * 100.0
+ filled := int(math.Round(pct / 10.0))
+ if filled < 0 {
+ filled = 0
+ }
+ if filled > 10 {
+ filled = 10
+ }
+
+ mode := g.colorMode(sess)
+
+ var fgColor int
+ switch {
+ case pct >= 70:
+ fgColor = 82
+ case pct >= 40:
+ fgColor = 220
+ default:
+ fgColor = 160
+ }
+
+ fillSpec := color.ColorSpec{Fg: fgColor}
+ emptySpec := color.ColorSpec{Fg: 238, Dim: true}
+
+ fillChar := "█"
+ emptyChar := "░"
+ if sess.Player != nil && !sess.Player.OptionBool("unicode") {
+ fillChar = "#"
+ emptyChar = "."
+ }
+
+ var sb strings.Builder
+ sb.WriteString("[")
+ sb.WriteString(color.Render(mode, fillSpec, strings.Repeat(fillChar, filled)))
+ sb.WriteString(color.Render(mode, emptySpec, strings.Repeat(emptyChar, 10-filled)))
+ sb.WriteString("]")
+ return sb.String()
+}