|
|
|
|
@ -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
|
|
|
|
|
|