gohan/examples/twinstick/system/printinfo.go

44 lines
1.1 KiB
Go

//go:build example
// +build example
package system
import (
"fmt"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type printInfoSystem struct {
img *ebiten.Image
op *ebiten.DrawImageOptions
player gohan.EntityID
}
func NewPrintInfoSystem(player gohan.EntityID) *printInfoSystem {
p := &printInfoSystem{
img: ebiten.NewImage(200, 100),
op: &ebiten.DrawImageOptions{},
player: player,
}
p.op.GeoM.Scale(2, 2)
return p
}
func (s *printInfoSystem) Matches(e gohan.EntityID) bool {
return e == s.player
}
func (s *printInfoSystem) Update(_ gohan.EntityID) error {
return gohan.ErrSystemWithoutUpdate
}
func (s *printInfoSystem) Draw(_ gohan.EntityID, screen *ebiten.Image) error {
s.img.Clear()
ebitenutil.DebugPrint(s.img, fmt.Sprintf("KEY WASD+MOUSE\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", gohan.ActiveEntities(), gohan.UpdatedEntities(), gohan.DrawnEntities(), ebiten.CurrentTPS(), ebiten.CurrentFPS()))
screen.DrawImage(s.img, s.op)
return nil
}