//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 { Velocity *component.Velocity Weapon *component.Weapon } func NewMovementInputSystem() *movementInputSystem { return &movementInputSystem{} } func (s *movementInputSystem) Update(entity gohan.Entity) error { if ebiten.IsKeyPressed(ebiten.KeyA) { s.Velocity.X -= 0.5 if s.Velocity.X < -5 { s.Velocity.X = -5 } } if ebiten.IsKeyPressed(ebiten.KeyD) { s.Velocity.X += 0.5 if s.Velocity.X > 5 { s.Velocity.X = 5 } } if ebiten.IsKeyPressed(ebiten.KeyW) { s.Velocity.Y -= 0.5 if s.Velocity.Y < -5 { s.Velocity.Y = -5 } } if ebiten.IsKeyPressed(ebiten.KeyS) { s.Velocity.Y += 0.5 if s.Velocity.Y > 5 { s.Velocity.Y = 5 } } return nil } func (s *movementInputSystem) Draw(_ gohan.Entity, _ *ebiten.Image) error { return gohan.ErrUnregister }