gohan/examples/twinstick/system/draw_player.go

52 lines
1.1 KiB
Go

//go:build example
// +build example
package system
import (
"code.rocketnine.space/tslocum/gohan"
"code.rocketnine.space/tslocum/gohan/examples/twinstick/asset"
"code.rocketnine.space/tslocum/gohan/examples/twinstick/component"
"github.com/hajimehoshi/ebiten/v2"
)
type drawPlayerSystem struct {
player gohan.Entity
op *ebiten.DrawImageOptions
}
func NewDrawPlayerSystem(player gohan.Entity) *drawPlayerSystem {
return &drawPlayerSystem{
player: player,
op: &ebiten.DrawImageOptions{},
}
}
func (s *drawPlayerSystem) Name() string {
return "DrawPlayer"
}
func (s *drawPlayerSystem) Needs() []gohan.ComponentID {
return []gohan.ComponentID{
component.PositionComponentID,
component.WeaponComponentID,
}
}
func (s *drawPlayerSystem) Uses() []gohan.ComponentID {
return nil
}
func (s *drawPlayerSystem) Update(_ *gohan.Context) error {
return gohan.ErrSystemWithoutUpdate
}
func (s *drawPlayerSystem) Draw(ctx *gohan.Context, screen *ebiten.Image) error {
position := component.Position(ctx)
s.op.GeoM.Reset()
s.op.GeoM.Translate(position.X-16, position.Y-16)
screen.DrawImage(asset.ImgWhiteSquare, s.op)
return nil
}