coyote-time

This commit is contained in:
Josh Deprez 2021-08-07 21:24:15 +10:00 committed by Josh Deprez
parent 3535cfe248
commit 89461950e2
2 changed files with 15 additions and 11 deletions

View file

@ -42,13 +42,13 @@ func init() {
{Frame: 6, Duration: 6},
{Frame: 7, Duration: 6},
{Frame: 8, Duration: 6},
{Frame: 9, Duration: 3},
{Frame: 9, Duration: 6},
},
},
"aw_run_right": {
Frames: []engine.AnimFrame{
{Frame: 10, Duration: 3},
{Frame: 11, Duration: 3},
{Frame: 11, Duration: 5},
{Frame: 12, Duration: 3},
{Frame: 13, Duration: 3},
},
@ -56,7 +56,7 @@ func init() {
"aw_run_left": {
Frames: []engine.AnimFrame{
{Frame: 14, Duration: 3},
{Frame: 15, Duration: 3},
{Frame: 15, Duration: 5},
{Frame: 16, Duration: 3},
{Frame: 17, Duration: 3},
},

View file

@ -16,8 +16,9 @@ func init() {
type Awakeman struct {
engine.Sprite
vx, vy float64
facingLeft bool
vx, vy float64
facingLeft bool
coyoteTimer int
animIdleLeft, animIdleRight, animRunLeft, animRunRight *engine.Anim
}
@ -27,21 +28,24 @@ func (aw *Awakeman) Update() error {
bounceDampen = 0.5
gravity = 0.3
jumpVelocity = -3.5
runVelocity = 1.5
runVelocity = 1.4
)
// Standing on something?
if aw.CollidesAt(aw.Pos.Add(image.Pt(0, 1))) {
// Not falling
aw.vy = 0
if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
// Jump?
aw.vy = jumpVelocity
}
// TODO: coyote-time
aw.coyoteTimer = 5
} else {
// Falling
aw.vy += gravity
if aw.coyoteTimer > 0 {
aw.coyoteTimer--
}
}
if aw.coyoteTimer > 0 && inpututil.IsKeyJustPressed(ebiten.KeySpace) {
// Jump
aw.vy = jumpVelocity
}
switch {
case ebiten.IsKeyPressed(ebiten.KeyLeft) || ebiten.IsKeyPressed(ebiten.KeyA):