coyote-time
This commit is contained in:
parent
3535cfe248
commit
89461950e2
2 changed files with 15 additions and 11 deletions
|
@ -42,13 +42,13 @@ func init() {
|
||||||
{Frame: 6, Duration: 6},
|
{Frame: 6, Duration: 6},
|
||||||
{Frame: 7, Duration: 6},
|
{Frame: 7, Duration: 6},
|
||||||
{Frame: 8, Duration: 6},
|
{Frame: 8, Duration: 6},
|
||||||
{Frame: 9, Duration: 3},
|
{Frame: 9, Duration: 6},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"aw_run_right": {
|
"aw_run_right": {
|
||||||
Frames: []engine.AnimFrame{
|
Frames: []engine.AnimFrame{
|
||||||
{Frame: 10, Duration: 3},
|
{Frame: 10, Duration: 3},
|
||||||
{Frame: 11, Duration: 3},
|
{Frame: 11, Duration: 5},
|
||||||
{Frame: 12, Duration: 3},
|
{Frame: 12, Duration: 3},
|
||||||
{Frame: 13, Duration: 3},
|
{Frame: 13, Duration: 3},
|
||||||
},
|
},
|
||||||
|
@ -56,7 +56,7 @@ func init() {
|
||||||
"aw_run_left": {
|
"aw_run_left": {
|
||||||
Frames: []engine.AnimFrame{
|
Frames: []engine.AnimFrame{
|
||||||
{Frame: 14, Duration: 3},
|
{Frame: 14, Duration: 3},
|
||||||
{Frame: 15, Duration: 3},
|
{Frame: 15, Duration: 5},
|
||||||
{Frame: 16, Duration: 3},
|
{Frame: 16, Duration: 3},
|
||||||
{Frame: 17, Duration: 3},
|
{Frame: 17, Duration: 3},
|
||||||
},
|
},
|
||||||
|
|
20
game/aw.go
20
game/aw.go
|
@ -16,8 +16,9 @@ func init() {
|
||||||
type Awakeman struct {
|
type Awakeman struct {
|
||||||
engine.Sprite
|
engine.Sprite
|
||||||
|
|
||||||
vx, vy float64
|
vx, vy float64
|
||||||
facingLeft bool
|
facingLeft bool
|
||||||
|
coyoteTimer int
|
||||||
|
|
||||||
animIdleLeft, animIdleRight, animRunLeft, animRunRight *engine.Anim
|
animIdleLeft, animIdleRight, animRunLeft, animRunRight *engine.Anim
|
||||||
}
|
}
|
||||||
|
@ -27,21 +28,24 @@ func (aw *Awakeman) Update() error {
|
||||||
bounceDampen = 0.5
|
bounceDampen = 0.5
|
||||||
gravity = 0.3
|
gravity = 0.3
|
||||||
jumpVelocity = -3.5
|
jumpVelocity = -3.5
|
||||||
runVelocity = 1.5
|
runVelocity = 1.4
|
||||||
)
|
)
|
||||||
|
|
||||||
// Standing on something?
|
// Standing on something?
|
||||||
if aw.CollidesAt(aw.Pos.Add(image.Pt(0, 1))) {
|
if aw.CollidesAt(aw.Pos.Add(image.Pt(0, 1))) {
|
||||||
// Not falling
|
// Not falling
|
||||||
aw.vy = 0
|
aw.vy = 0
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
|
aw.coyoteTimer = 5
|
||||||
// Jump?
|
|
||||||
aw.vy = jumpVelocity
|
|
||||||
}
|
|
||||||
// TODO: coyote-time
|
|
||||||
} else {
|
} else {
|
||||||
// Falling
|
// Falling
|
||||||
aw.vy += gravity
|
aw.vy += gravity
|
||||||
|
if aw.coyoteTimer > 0 {
|
||||||
|
aw.coyoteTimer--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if aw.coyoteTimer > 0 && inpututil.IsKeyJustPressed(ebiten.KeySpace) {
|
||||||
|
// Jump
|
||||||
|
aw.vy = jumpVelocity
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case ebiten.IsKeyPressed(ebiten.KeyLeft) || ebiten.IsKeyPressed(ebiten.KeyA):
|
case ebiten.IsKeyPressed(ebiten.KeyLeft) || ebiten.IsKeyPressed(ebiten.KeyA):
|
||||||
|
|
Loading…
Reference in a new issue