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,54 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
)
|
||||
|
||||
// Effect is a buff, or a debuff, with turns left.
|
||||
type Effect struct {
|
||||
Sprite *pixel.Sprite
|
||||
Name string
|
||||
// Turns left; zero hides the count.
|
||||
Turns int
|
||||
Debuff bool
|
||||
}
|
||||
|
||||
type StatusEffectsOptions struct{}
|
||||
|
||||
// StatusEffects rows effect icons: buffs edged Good, debuffs Bad.
|
||||
func StatusEffects(c *ui.Context, text string, effects []Effect, o StatusEffectsOptions) *ui.Element {
|
||||
k := pixel.K(c)
|
||||
parts := make([]string, len(effects))
|
||||
for i, ef := range effects {
|
||||
if ef.Sprite == nil || ef.Turns < 0 {
|
||||
panic(fmt.Sprintf("game: effect %q has no sprite or %d turns", ef.Name, ef.Turns))
|
||||
}
|
||||
parts[i] = ef.Name
|
||||
if ef.Turns > 0 {
|
||||
parts[i] += " " + strconv.Itoa(ef.Turns)
|
||||
}
|
||||
}
|
||||
return ui.Box(c).Role(ui.RoleImage).Label(text).Description(strings.Join(parts, ", ")).Size(k.D(len(effects)*17), k.D(16)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
g := k.Canvas(p, r)
|
||||
for i, ef := range effects {
|
||||
x, edge := i*17, pixel.Good
|
||||
if ef.Debuff {
|
||||
edge = pixel.Bad
|
||||
}
|
||||
g.Frame(x, 0, 16, 16, pixel.Flat, pixel.Well)
|
||||
g.Rect(x+1, 1, 14, 1, edge)
|
||||
g.Sprite(x+(16-ef.Sprite.W)/2, (16-ef.Sprite.H)/2, ef.Sprite, 0, pixel.Ink, 1)
|
||||
if ef.Turns > 0 {
|
||||
n := strconv.Itoa(ef.Turns)
|
||||
g.Rect(x+15-pixel.MicroWidth(n)-2, 9, pixel.MicroWidth(n)+2, 7, edge)
|
||||
g.Micro(x+14-pixel.MicroWidth(n), 10, n, pixel.AccentInk, 1)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user