Skip to content

Instantly share code, notes, and snippets.

@plutov
Created February 22, 2024 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plutov/375401aeae661980ab0ac89788f1bad3 to your computer and use it in GitHub Desktop.
Save plutov/375401aeae661980ab0ac89788f1bad3 to your computer and use it in GitHub Desktop.
package snake
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Input struct{}
func NewInput() *Input {
return &Input{}
}
func (i *Input) Dir() (ebiten.Key, bool) {
if inpututil.IsKeyJustPressed(ebiten.KeyArrowUp) {
return ebiten.KeyArrowUp, true
}
if inpututil.IsKeyJustPressed(ebiten.KeyArrowLeft) {
return ebiten.KeyArrowLeft, true
}
if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) {
return ebiten.KeyArrowRight, true
}
if inpututil.IsKeyJustPressed(ebiten.KeyArrowDown) {
return ebiten.KeyArrowDown, true
}
return 0, false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment