Files
8bitMyGoUI/game/bossbar.go
T
ZacharyZhang-NY f48075230f Add game components 246-268; data.DrawSlot, Canvas.TextVeil
Health, mana and experience bars, quarter hearts, lives, a spinning
coin counter, score board, stage timer, minimap with fog, compass,
hotbar, paper-doll equipment, skill tree, skill buttons with cooldown
wipes, status effects, a boss bar, damage numbers, quest log and
tracker, party frames, character sheet, level-up screen and shop.
data exports DrawSlot so every slot looks alike; pixel adds TextVeil
for dissolving text. Messages the font cannot draw are fixed and
TestMessagesHaveGlyphs holds every message to the font.
2026-10-12 01:53:20 -04:00

44 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package game
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type BossBarOptions struct {
// Width is in dots; zero means 200.
Width int
// Phases are where the boss changes, as fractions: 0.5.
Phases []float64
}
// BossBar is a wide bar under the name, phases marked.
func BossBar(c *ui.Context, name string, hp, full int, o BossBarOptions) *ui.Element {
k := pixel.K(c)
amount("BossBar hp", hp, full)
for _, f := range o.Phases {
if !(f > 0 && f < 1) {
panic(fmt.Sprintf("game: BossBar phase %v outside 0–1", f))
}
}
w := pixel.Or("BossBar Width", o.Width, 200)
if need := icon.Skull.W + 3 + pixel.Measure(name); w < need {
panic(fmt.Sprintf("game: BossBar Width %d is under the %d its name needs", w, need))
}
return ui.Box(c).Role(ui.RoleMeter).Label(name).Description(ratio(hp, full)).Size(k.D(w), k.D(pixel.LineHeight+12)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Sprite(0, 2, icon.Skull, 0, pixel.Bad, 1)
g.Text(icon.Skull.W+3, 0, name, pixel.Ink, 1)
meter(g, 0, pixel.LineHeight, w, 12, float64(hp)/float64(full), pixel.Bad)
for _, f := range o.Phases {
x := 2 + int(f*float64(w-4))
g.VLine(x, pixel.LineHeight-2, 14, pixel.Ink)
g.Rect(x-1, pixel.LineHeight-2, 3, 1, pixel.Ink)
}
})
}