key just pressed

This commit is contained in:
Josh Deprez 2021-08-03 20:09:22 +10:00 committed by Josh Deprez
parent 4ea31970e5
commit d4dcd952a4

View file

@ -7,6 +7,7 @@ import (
"math" "math"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
) )
const gravity = 0.5 const gravity = 0.5
@ -63,7 +64,7 @@ func (a *Actor) Update() error {
if a.collidesAt(a.Position.Add(image.Pt(0, 1))) { if a.collidesAt(a.Position.Add(image.Pt(0, 1))) {
// Not falling // Not falling
a.vy = 0 a.vy = 0
if ebiten.IsKeyPressed(ebiten.KeySpace) { if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
// Jump? // Jump?
a.vy = -7 a.vy = -7
} }