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
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.EntityID) bool { |
|
position := entity.Component(component.PositionComponentID) |
|
bullet := entity.Component(component.BulletComponentID) |
|
|
|
return position != nil && bullet != nil |
|
} |
|
|
|
func (s *DrawBulletsSystem) Update(_ gohan.EntityID) error { |
|
return gohan.ErrSystemWithoutUpdate |
|
} |
|
|
|
func (s *DrawBulletsSystem) Draw(entity gohan.EntityID, screen *ebiten.Image) error { |
|
position := entity.Component(component.PositionComponentID).(*component.PositionComponent) |
|
|
|
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 |
|
}
|
|
|