This commit is contained in:
Josh Deprez 2021-09-02 17:24:08 +10:00
parent ac39e393ba
commit 82559faa66
3 changed files with 14 additions and 4 deletions

View file

@ -74,7 +74,7 @@ func (a *Actor) MoveY(dy float64, onCollide func()) {
} }
func (a *Actor) MoveZ(dz float64, onCollide func()) { func (a *Actor) MoveZ(dz float64, onCollide func()) {
a.yRem += dz a.zRem += dz
move := int(a.zRem + 0.5) move := int(a.zRem + 0.5)
if move == 0 { if move == 0 {
return return
@ -82,7 +82,7 @@ func (a *Actor) MoveZ(dz float64, onCollide func()) {
a.zRem -= float64(move) a.zRem -= float64(move)
sign := sign(move) sign := sign(move)
for move != 0 { for move != 0 {
if a.CollidesAt(a.Pos.Add(Pt3(0, 0, 0))) { if a.CollidesAt(a.Pos.Add(Pt3(0, 0, sign))) {
if onCollide != nil { if onCollide != nil {
onCollide() onCollide()
} }

Binary file not shown.

View file

@ -32,7 +32,7 @@ type Awakeman struct {
camera *engine.Camera camera *engine.Camera
toast *engine.DebugToast toast *engine.DebugToast
vx, vy float64 vx, vy, vz float64
facingLeft bool facingLeft bool
coyoteTimer int coyoteTimer int
jumpBuffer int jumpBuffer int
@ -114,7 +114,7 @@ func (aw *Awakeman) realUpdate() error {
// and // and
// s = (v_0 + v) / 2. // s = (v_0 + v) / 2.
// Capture current v_0 to use later. // Capture current v_0 to use later.
ux, uy := aw.vx, aw.vy ux, uy, uz := aw.vx, aw.vy, aw.vz
// Has traction? // Has traction?
if aw.Sprite.Actor.CollidesAt(aw.Sprite.Actor.Pos.Add(engine.Pt3(0, 1, 0))) { if aw.Sprite.Actor.CollidesAt(aw.Sprite.Actor.Pos.Add(engine.Pt3(0, 1, 0))) {
@ -170,6 +170,15 @@ func (aw *Awakeman) realUpdate() error {
aw.Sprite.SetAnim(aw.animIdleLeft) aw.Sprite.SetAnim(aw.animIdleLeft)
} }
} }
// Up and down (away and closer)
switch {
case ebiten.IsKeyPressed(ebiten.KeyUp) || ebiten.IsKeyPressed(ebiten.KeyW):
aw.vz = -runVelocity
case ebiten.IsKeyPressed(ebiten.KeyDown) || ebiten.IsKeyPressed(ebiten.KeyS):
aw.vz = runVelocity
default:
aw.vz = 0
}
// s = (v_0 + v) / 2. // s = (v_0 + v) / 2.
aw.Sprite.Actor.MoveX((ux+aw.vx)/2, nil) aw.Sprite.Actor.MoveX((ux+aw.vx)/2, nil)
@ -181,6 +190,7 @@ func (aw *Awakeman) realUpdate() error {
aw.vy = 0 aw.vy = 0
} }
}) })
aw.Sprite.Actor.MoveZ((uz+aw.vz)/2, nil)
return nil return nil
} }