You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 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.EntityID
op *ebiten.DrawImageOptions
}
func NewDrawPlayerSystem(player gohan.EntityID) *drawPlayerSystem {
return &drawPlayerSystem{
player: player,
op: &ebiten.DrawImageOptions{},
}
}
func (s *drawPlayerSystem) Matches(entity gohan.EntityID) bool {
return entity == s.player
}
func (s *drawPlayerSystem) Update(_ gohan.EntityID) error {
return gohan.ErrSystemWithoutUpdate
}
func (s *drawPlayerSystem) Draw(entity gohan.EntityID, screen *ebiten.Image) error {
position := entity.Component(component.PositionComponentID).(*component.PositionComponent)
s.op.GeoM.Reset()
s.op.GeoM.Translate(position.X-16, position.Y-16)
screen.DrawImage(asset.ImgWhiteSquare, s.op)
return nil
}