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.
This commit is contained in:
42 files changed
+3260
-26
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
)
|
||||
|
||||
type SkillButtonOptions struct {
|
||||
Disabled bool
|
||||
}
|
||||
|
||||
type SkillButtonResult struct {
|
||||
Element *ui.Element
|
||||
// Clicked is a press while the skill is ready.
|
||||
Clicked bool
|
||||
}
|
||||
|
||||
// SkillButton shows a skill, its key and a cooldown wipe.
|
||||
func SkillButton(c *ui.Context, text string, sprite *pixel.Sprite, key string, cooldown float64, o SkillButtonOptions) SkillButtonResult {
|
||||
k := pixel.K(c)
|
||||
if sprite == nil || !(cooldown >= 0 && cooldown <= 1) || !pixel.MicroOK(key) {
|
||||
panic(fmt.Sprintf("game: SkillButton %q needs a sprite, a micro key %q, a cooldown in 0–1 (%v)", text, key, cooldown))
|
||||
}
|
||||
shell, base, st := pixel.Shell(c, func() *ui.Element { return ui.ButtonBase(c).Label(text).Disabled(o.Disabled) })
|
||||
res := SkillButtonResult{Element: shell, Clicked: base.Clicked() && cooldown == 0}
|
||||
if res.Clicked {
|
||||
slog.Debug("8bit: skill", "label", text)
|
||||
}
|
||||
state := k.Msg("ready")
|
||||
if cooldown > 0 {
|
||||
state = strconv.Itoa(int(math.Ceil(cooldown*100))) + "%"
|
||||
}
|
||||
base.Description(state)
|
||||
shell.Size(k.D(24), k.D(24)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
g := k.Canvas(p, r)
|
||||
style := pixel.Raised
|
||||
if st.Press {
|
||||
style = pixel.Sunken
|
||||
}
|
||||
g.Frame(0, 0, 24, 24, style, pixel.Face)
|
||||
g.Sprite((24-sprite.W)/2, (24-sprite.H)/2, sprite, 0, pixel.Ink, 1)
|
||||
// The wipe clears from twelve, clockwise, as the cooldown ends.
|
||||
for y := 2; y < 22; y++ {
|
||||
for x := 2; x < 22; x++ {
|
||||
a := math.Atan2(float64(x)-11.5, 11.5-float64(y)) / (2 * math.Pi)
|
||||
if a < 0 {
|
||||
a++
|
||||
}
|
||||
if a >= 1-cooldown {
|
||||
g.Veil(x, y, 1, 1, pixel.Edge, 11)
|
||||
}
|
||||
}
|
||||
}
|
||||
kw := pixel.MicroWidth(key)
|
||||
g.Rect(1, 1, kw+3, 8, pixel.Lit)
|
||||
g.Micro(2, 2, key, pixel.Ink, 1)
|
||||
g.Finish(st)
|
||||
})
|
||||
return res
|
||||
}
|
||||
Reference in new issue
Block a user