Files
8bitMyGoUI/game/quest.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

48 lines
992 B
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"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// Objective is a quest step, Have of Need (≥ 1).
type Objective struct {
Text string
Have, Need int
}
// Quest is a title and its objectives.
type Quest struct {
Title string
Objectives []Objective
}
// check fails on objectives past their need.
func (q Quest) check() {
for _, ob := range q.Objectives {
if ob.Need < 1 || ob.Have < 0 || ob.Have > ob.Need {
panic(fmt.Sprintf("game: quest %q objective %q has %d of %d", q.Title, ob.Text, ob.Have, ob.Need))
}
}
}
// done is whether every objective is met.
func (q Quest) done() bool {
for _, ob := range q.Objectives {
if ob.Have < ob.Need {
return false
}
}
return true
}
// tick marks a 7×7 box, checked when done.
func tick(g pixel.Canvas, x, y int, done bool) {
g.Frame(x, y, 7, 7, pixel.Flat, pixel.Well)
if done {
g.Line(x+1, y+3, x+2, y+5, pixel.Good)
g.Line(x+3, y+4, x+5, y+1, pixel.Good)
}
}