switched to ebitengine-input

This commit is contained in:
2024-04-16 19:10:32 +02:00
parent b7383f065f
commit abc93d4d57
11 changed files with 77 additions and 16 deletions

View File

@@ -12,9 +12,9 @@ import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/mlange-42/arche/ecs"
"github.com/mlange-42/arche/generic"
input "github.com/quasilyte/ebitengine-input"
)
type PlayerSystem struct {
@@ -22,15 +22,18 @@ type PlayerSystem struct {
Selector *generic.Filter4[Position, Velocity, Player, Renderable]
GridContainer *grid.GridContainer
Width, Height int
Input *input.Handler
}
func NewPlayerSystem(world *ecs.World, gridcontainer *grid.GridContainer, width, height int) System {
func NewPlayerSystem(world *ecs.World, gridcontainer *grid.GridContainer,
width, height int, handler *input.Handler) System {
system := &PlayerSystem{
Selector: generic.NewFilter4[Position, Velocity, Player, Renderable](),
GridContainer: gridcontainer,
World: world,
Width: width,
Height: height,
Input: handler,
}
return system
@@ -167,7 +170,7 @@ func (system *PlayerSystem) SwitchPlayers() {
render.Image = player.SwitchSprite()
} else {
// many players, switch when requested
if inpututil.IsKeyJustPressed(ebiten.KeyTab) {
if system.Input.ActionIsJustPressed(SwitchPlayer) {
slog.Debug("switch players")
if player.IsPrimary {
player.IsPrimary = false
@@ -192,16 +195,16 @@ func (system *PlayerSystem) CheckMovement(
if !velocity.Moving() {
switch {
case inpututil.IsKeyJustPressed(ebiten.KeyRight):
case system.Input.ActionIsJustPressed(MoveRight):
velocity.Change(East)
moved = true
case inpututil.IsKeyJustPressed(ebiten.KeyLeft):
case system.Input.ActionIsJustPressed(MoveLeft):
velocity.Change(West)
moved = true
case inpututil.IsKeyJustPressed(ebiten.KeyDown):
case system.Input.ActionIsPressed(MoveDown):
velocity.Change(South)
moved = true
case inpututil.IsKeyJustPressed(ebiten.KeyUp):
case system.Input.ActionIsJustPressed(MoveUp):
velocity.Change(North)
moved = true
}