deflect on edge hit
All checks were successful
build rgb-board / build (push) Successful in 3m59s

This commit is contained in:
Nathan Wagner
2025-06-12 18:40:45 +00:00
parent e4a47f3b76
commit e33a88106c

View File

@@ -69,11 +69,16 @@ func (a *Animation) updateMarioPosition() {
marioY += centerY
// Check for edge collision and change direction if necessary
if marioX < 0 || marioX >= a.ctx.Width() {
a.mario.angle = -a.mario.angle
if marioX < 0 {
a.mario.angle = -a.mario.angle + math.Pi // Reflect horizontally and adjust angle
} else if marioX >= a.ctx.Width() {
a.mario.angle = -a.mario.angle + math.Pi // Reflect horizontally and adjust angle
}
if marioY < 0 || marioY >= a.ctx.Height() {
a.mario.angle = math.Pi + (math.Pi - a.mario.angle)
if marioY < 0 {
a.mario.angle = math.Pi - a.mario.angle // Flip vertically and adjust angle
} else if marioY >= a.ctx.Height() {
a.mario.angle = math.Pi - a.mario.angle // Flip vertically and adjust angle
}
a.mario.position.X = marioX