From e33a88106c069b1e55194a2c6f195eaf80c31ce5 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Thu, 12 Jun 2025 18:40:45 +0000 Subject: [PATCH] deflect on edge hit --- animationMario.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/animationMario.go b/animationMario.go index 9242f74..f5da73b 100644 --- a/animationMario.go +++ b/animationMario.go @@ -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