From 10cafdc2099b7d010fa2e936d4fd5b701e089562 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 31 Oct 2025 19:48:17 +0000 Subject: [PATCH] fix teleporting --- animationMario.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/animationMario.go b/animationMario.go index 1fa547a..cb53655 100644 --- a/animationMario.go +++ b/animationMario.go @@ -84,6 +84,18 @@ func (a *Animation) updateMarioPosition() { minCenterY := halfH maxCenterY := a.ctx.Height() - 1 - halfH + // If the sprite is larger than the panel in a dimension, collapse + // the allowed center range to the panel center so we don't get + // immediate collisions every frame which makes Mario flash. + if maxCenterX < minCenterX { + minCenterX = centerX + maxCenterX = centerX + } + if maxCenterY < minCenterY { + minCenterY = centerY + maxCenterY = centerY + } + // parametric angle before any reflection t := a.mario.angle @@ -95,6 +107,16 @@ func (a *Animation) updateMarioPosition() { collidedX := marioX < minCenterX || marioX > maxCenterX collidedY := marioY < minCenterY || marioY > maxCenterY + // If allowed range collapsed to the center, don't reflect on that axis + // because reflection would keep flipping every frame. Treat that as + // non-colliding for reflection purposes (we'll clamp position later). + if minCenterX == maxCenterX { + collidedX = false + } + if minCenterY == maxCenterY { + collidedY = false + } + // Reflect the parametric angle correctly: // - For horizontal collision we want cos(t_new) = -cos(t) => t_new = Pi - t // - For vertical collision we want sin(t_new) = -sin(t) => t_new = -t