Added steps counter.

This commit is contained in:
Sander Schobers 2019-12-23 23:42:33 +01:00
parent 227c451ca6
commit a6cb582254
3 changed files with 13 additions and 0 deletions

View File

@ -25,6 +25,8 @@ func (f *Fonts) Destroy() {
f.fonts = nil f.fonts = nil
} }
func (f *Fonts) Len() int { return len(f.fonts) }
func (f *Fonts) Load(path string, size int, name string) error { func (f *Fonts) Load(path string, size int, name string) error {
font, err := allg5.LoadTTFFont(path, size) font, err := allg5.LoadTTFFont(path, size)
if err != nil { if err != nil {

View File

@ -64,6 +64,10 @@ func (g *Game) loadFonts() error {
if err != nil { if err != nil {
return err return err
} }
err = g.ui.Fonts().LoadFonts(alui.FontDescription{Path: openSansPath, Name: "steps", Size: 36})
if err != nil {
return err
}
err = g.ui.Fonts().LoadFonts(alui.FontDescription{Path: firaMonoPath, Name: "console", Size: 12}) err = g.ui.Fonts().LoadFonts(alui.FontDescription{Path: firaMonoPath, Name: "console", Size: 12})
if err != nil { if err != nil {
return err return err
@ -156,6 +160,7 @@ func (g *Game) loadAssets() error {
if err != nil { if err != nil {
return err return err
} }
log.Printf("Loaded %d fonts.\n", g.ui.Fonts().Len())
log.Println("Loading sprites") log.Println("Loading sprites")
// err = g.loadSprites("dragon") // err = g.loadSprites("dragon")

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"log" "log"
"sort" "sort"
"time" "time"
@ -331,4 +332,9 @@ func (s *playLevel) Render(ctx *alui.Context, bounds geom.RectangleF32) {
crate.DrawOptions(scrPos.X, scrPos.Y, opts) crate.DrawOptions(scrPos.X, scrPos.Y, opts)
} }
} }
steps := fmt.Sprintf("STEPS: %d", s.steps)
stepsFont := ctx.Fonts.Get("steps")
stepsWidth := stepsFont.TextWidth(steps)
stepsFont.Draw(.5*(bounds.Dx()-stepsWidth), 24, allg5.NewColor(255, 255, 255), allg5.AlignCenter, steps)
} }