gohan/examples/twinstick/system/printinfo.go

50 lines
1.2 KiB
Go
Raw Normal View History

2021-11-19 04:13:28 +00:00
//go:build example
// +build example
package system
import (
"fmt"
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan/examples/twinstick/component"
"code.rocketnine.space/tslocum/gohan/examples/twinstick/world"
2021-11-19 04:13:28 +00:00
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
type printInfoSystem struct {
img *ebiten.Image
op *ebiten.DrawImageOptions
player gohan.Entity
2021-11-19 04:13:28 +00:00
}
func NewPrintInfoSystem(player gohan.Entity) *printInfoSystem {
2021-11-19 04:13:28 +00:00
p := &printInfoSystem{
img: ebiten.NewImage(200, 100),
op: &ebiten.DrawImageOptions{},
player: player,
}
p.op.GeoM.Scale(2, 2)
return p
}
func (s *printInfoSystem) Components() []gohan.ComponentID {
return []gohan.ComponentID{
component.WeaponComponentID,
}
2021-11-19 04:13:28 +00:00
}
func (s *printInfoSystem) Update(ctx *gohan.Context) error {
2021-11-19 04:13:28 +00:00
return gohan.ErrSystemWithoutUpdate
}
func (s *printInfoSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
w := world.World
2021-11-19 04:13:28 +00:00
s.img.Clear()
ebitenutil.DebugPrint(s.img, fmt.Sprintf("KEY WASD+MOUSE\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", w.ActiveEntities(), w.UpdatedEntities(), w.DrawnEntities(), ebiten.CurrentTPS(), ebiten.CurrentFPS()))
2021-11-19 04:13:28 +00:00
screen.DrawImage(s.img, s.op)
return nil
}