zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

commit 0c407d734f17931ab22e4b3a6a1003c1b1613421
parent 419791362d4a77f95851e13095c7ae0920a56183
Author: bsandro <brian.drosan@gmail.com>
Date:   Tue, 12 Oct 2021 22:40:12 +0300

Handle simultaneous key presses properly

Diffstat:
Mmain.go | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/main.go b/main.go @@ -45,19 +45,23 @@ func (g *Game) Init() error { func (g *Game) Update() error { g.PressedKeys = inpututil.AppendPressedKeys(g.PressedKeys[:0]) for _, key := range g.PressedKeys { - switch key { - case ebiten.KeyArrowLeft: + if key == ebiten.KeyQ { + os.Exit(0) + } + + if key == ebiten.KeyArrowLeft { g.Cam.ChangeX(-cameraStep) - case ebiten.KeyArrowRight: + } + if key == ebiten.KeyArrowRight { g.Cam.ChangeX(cameraStep) - case ebiten.KeyArrowUp: + } + if key == ebiten.KeyArrowUp { g.Cam.ChangeY(-cameraStep) - case ebiten.KeyArrowDown: + } + if key == ebiten.KeyArrowDown { g.Cam.ChangeY(cameraStep) - case ebiten.KeyQ: - os.Exit(0) - default: } + } return nil