leap-before-look-then-undo

This commit is contained in:
Josh Deprez 2021-09-04 16:28:33 +10:00
parent f5f0c447aa
commit f8eacc5904

View file

@ -42,16 +42,18 @@ func (a *Actor) MoveX(x float64, onCollide func()) {
a.xRem -= float64(move) a.xRem -= float64(move)
sign := sign(move) sign := sign(move)
for move != 0 { for move != 0 {
if a.CollidesAt(a.Pos.Add(Pt3(sign, 0, 0))) { a.Pos.X += sign
move -= sign
if !a.CollidesAt(a.Pos) {
continue
}
if onCollide != nil { if onCollide != nil {
onCollide() onCollide()
} }
a.Pos.X -= sign
a.xRem = 0 a.xRem = 0
return return
} }
a.Pos.X += sign
move -= sign
}
} }
func (a *Actor) MoveY(y float64, onCollide func()) { func (a *Actor) MoveY(y float64, onCollide func()) {
@ -63,16 +65,18 @@ func (a *Actor) MoveY(y float64, onCollide func()) {
a.yRem -= float64(move) a.yRem -= float64(move)
sign := sign(move) sign := sign(move)
for move != 0 { for move != 0 {
if a.CollidesAt(a.Pos.Add(Pt3(0, sign, 0))) { a.Pos.Y += sign
move -= sign
if !a.CollidesAt(a.Pos) {
continue
}
if onCollide != nil { if onCollide != nil {
onCollide() onCollide()
} }
a.Pos.Y -= sign
a.yRem = 0 a.yRem = 0
return return
} }
a.Pos.Y += sign
move -= sign
}
} }
func (a *Actor) MoveZ(z float64, onCollide func()) { func (a *Actor) MoveZ(z float64, onCollide func()) {
@ -84,16 +88,18 @@ func (a *Actor) MoveZ(z 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, sign))) { a.Pos.Z += sign
move -= sign
if !a.CollidesAt(a.Pos) {
continue
}
if onCollide != nil { if onCollide != nil {
onCollide() onCollide()
} }
a.Pos.Z -= sign
a.zRem = 0 a.zRem = 0
return return
} }
a.Pos.Z += sign
move -= sign
}
} }
func (a *Actor) Prepare(g *Game) error { func (a *Actor) Prepare(g *Game) error {