//go:build example // +build example package system import ( "code.rocketnine.space/tslocum/gohan" "code.rocketnine.space/tslocum/gohan/examples/twinstick/component" "github.com/hajimehoshi/ebiten/v2" ) type movementInputSystem struct { player gohan.Entity } func NewMovementInputSystem(player gohan.Entity) *movementInputSystem { return &movementInputSystem{ player: player, } } func (s *movementInputSystem) Matches(e gohan.Entity) bool { return e == s.player } func (s *movementInputSystem) Update(e gohan.Entity) error { velocity := component.Velocity(s.player) if ebiten.IsKeyPressed(ebiten.KeyA) { velocity.X -= 0.5 if velocity.X < -5 { velocity.X = -5 } } if ebiten.IsKeyPressed(ebiten.KeyD) { velocity.X += 0.5 if velocity.X > 5 { velocity.X = 5 } } if ebiten.IsKeyPressed(ebiten.KeyW) { velocity.Y -= 0.5 if velocity.Y < -5 { velocity.Y = -5 } } if ebiten.IsKeyPressed(ebiten.KeyS) { velocity.Y += 0.5 if velocity.Y > 5 { velocity.Y = 5 } } return nil } func (s *movementInputSystem) Draw(_ gohan.Entity, _ *ebiten.Image) error { return gohan.ErrSystemWithoutDraw }