Entity Component System framework for Ebitengine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

//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 DrawBulletsSystem struct {
op *ebiten.DrawImageOptions
}
func NewDrawBulletsSystem() *DrawBulletsSystem {
return &DrawBulletsSystem{
op: &ebiten.DrawImageOptions{},
}
}
func (s *DrawBulletsSystem) Matches(entity gohan.Entity) bool {
position := entity.Component(component.PositionComponentID)
bullet := entity.Component(component.BulletComponentID)
return position != nil && bullet != nil
}
func (s *DrawBulletsSystem) Update(_ gohan.Entity) error {
return gohan.ErrSystemWithoutUpdate
}
func (s *DrawBulletsSystem) Draw(entity gohan.Entity, screen *ebiten.Image) error {
position := component.Position(entity)
s.op.GeoM.Reset()
s.op.GeoM.Translate(-16, -16)
s.op.GeoM.Scale(0.5, 0.5)
s.op.GeoM.Translate(position.X, position.Y)
screen.DrawImage(asset.ImgWhiteSquare, s.op)
return nil
}