switched to ebitengine-input
This commit is contained in:
12
game/game.go
12
game/game.go
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/mlange-42/arche/ecs"
|
||||
input "github.com/quasilyte/ebitengine-input"
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
@@ -20,6 +21,8 @@ type Game struct {
|
||||
Observer *observers.GameObserver
|
||||
Levels []*Level // fed in PlayScene.GenerateLevels()
|
||||
Config *config.Config
|
||||
InputSystem input.System
|
||||
Input *input.Handler
|
||||
}
|
||||
|
||||
func NewGame(width, height, cellsize int, cfg *config.Config, startscene SceneName) *Game {
|
||||
@@ -38,6 +41,12 @@ func NewGame(width, height, cellsize int, cfg *config.Config, startscene SceneNa
|
||||
game.Observer = observers.NewGameObserver(
|
||||
&world, cfg.Startlevel, width, height, cellsize)
|
||||
|
||||
game.InputSystem.Init(input.SystemConfig{
|
||||
DevicesEnabled: input.AnyDevice,
|
||||
})
|
||||
|
||||
game.Input = game.InputSystem.NewHandler(0, game.Config.Keymap)
|
||||
|
||||
game.Scenes[Welcome] = NewWelcomeScene(game)
|
||||
game.Scenes[Menu] = NewMenuScene(game)
|
||||
game.Scenes[About] = NewAboutScene(game)
|
||||
@@ -57,6 +66,9 @@ func (game *Game) GetCurrentScene() Scene {
|
||||
}
|
||||
|
||||
func (game *Game) Update() error {
|
||||
// update ebitengine-input
|
||||
game.InputSystem.Update()
|
||||
|
||||
// handle level ends
|
||||
timer := game.Observer.StopTimer
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ func NewLevel(game *Game, cellsize int, plan *ldtkgo.Level) *Level {
|
||||
systemlist = append(systemlist, systems.NewPairSystem(game.World, gridcontainer))
|
||||
|
||||
systemlist = append(systemlist,
|
||||
systems.NewPlayerSystem(game.World, gridcontainer, game.ScreenWidth, game.ScreenHeight))
|
||||
systems.NewPlayerSystem(game.World, gridcontainer,
|
||||
game.ScreenWidth, game.ScreenHeight, game.Input))
|
||||
|
||||
systemlist = append(systemlist, systems.NewAnimationSystem(game.World, game.Cellsize))
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"openquell/config"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
type PlayScene struct {
|
||||
@@ -73,10 +72,10 @@ func (scene *PlayScene) Update() error {
|
||||
scene.Levels[scene.CurrentLevel].Update()
|
||||
|
||||
switch {
|
||||
case inpututil.IsKeyJustPressed(ebiten.KeyEscape):
|
||||
case scene.Game.Input.ActionIsJustPressed(config.Abort):
|
||||
scene.SetNext(Popup)
|
||||
|
||||
case inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft):
|
||||
case scene.Game.Input.ActionIsJustPressed(config.Activate):
|
||||
// ok we're checking the menu button here, but drawing it in hud_system,
|
||||
// because systems can't switch scenes
|
||||
if image.Pt(ebiten.CursorPosition()).In(scene.MenuRect) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/ebitenui/ebitenui/widget"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
type PopupScene struct {
|
||||
@@ -53,7 +52,7 @@ func (scene *PopupScene) Clearscreen() bool {
|
||||
func (scene *PopupScene) Update() error {
|
||||
scene.Ui.Update()
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
|
||||
if scene.Game.Input.ActionIsJustPressed(config.Abort) {
|
||||
scene.SetNext(Play)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/ebitenui/ebitenui/widget"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
)
|
||||
|
||||
type SelectScene struct {
|
||||
@@ -56,7 +55,7 @@ func (scene *SelectScene) Clearscreen() bool {
|
||||
func (scene *SelectScene) Update() error {
|
||||
scene.Ui.Update()
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
|
||||
if scene.Game.Input.ActionIsJustPressed(config.Abort) {
|
||||
scene.SetNext(Menu)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func (scene *WelcomeScene) Clearscreen() bool {
|
||||
|
||||
func (scene *WelcomeScene) Update() error {
|
||||
switch {
|
||||
case ebiten.IsKeyPressed(ebiten.KeyEnter):
|
||||
case scene.Game.Input.AnyKeyJustPressed():
|
||||
scene.SetNext(Menu)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user