Created
February 22, 2024 10:06
-
-
Save plutov/375401aeae661980ab0ac89788f1bad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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