|
|
@ -75,11 +75,12 @@ func (a *Animation) updateMarioPosition() {
|
|
|
|
amplitude = 4 // Amplitude of the sine wave
|
|
|
|
amplitude = 4 // Amplitude of the sine wave
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
currentTime := float64(a.ctx.Width()) / wavelength // Calculate current time based on position
|
|
|
|
currentTime := float64(a.mario.position.X) / wavelength // Calculate current time based on Mario's X position
|
|
|
|
|
|
|
|
|
|
|
|
a.mario.position.X += int(amplitude*math.Sin(2*math.Pi*currentTime/wavelength)) + a.mario.dir.X
|
|
|
|
a.mario.position.X += int(amplitude*math.Sin(2*math.Pi*currentTime/wavelength)) + a.mario.dir.X
|
|
|
|
a.mario.position.Y += a.mario.dir.Y
|
|
|
|
a.mario.position.Y += a.mario.dir.Y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure Mario stays within the display boundaries and reverses direction when necessary.
|
|
|
|
if a.mario.position.Y+a.height > a.ctx.Height() {
|
|
|
|
if a.mario.position.Y+a.height > a.ctx.Height() {
|
|
|
|
a.mario.position.Y = a.ctx.Height() - a.height // Reset Y position to the top boundary
|
|
|
|
a.mario.position.Y = a.ctx.Height() - a.height // Reset Y position to the top boundary
|
|
|
|
a.mario.updown = "marioUp"
|
|
|
|
a.mario.updown = "marioUp"
|
|
|
@ -91,10 +92,8 @@ func (a *Animation) updateMarioPosition() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if a.mario.position.X+a.width > a.ctx.Width() {
|
|
|
|
if a.mario.position.X+a.width > a.ctx.Width() {
|
|
|
|
a.mario.position.X = a.ctx.Width() - a.width // Reset X position to the left boundary
|
|
|
|
a.mario.position.X -= (a.mario.position.X + a.width - a.ctx.Width()) // Wrap around to the left side
|
|
|
|
a.mario.dir.X = -a.mario.dir.X // Reverse direction when hitting right edge
|
|
|
|
|
|
|
|
} else if a.mario.position.X < 0 {
|
|
|
|
} else if a.mario.position.X < 0 {
|
|
|
|
a.mario.position.X = 0 // Reset X position to the right boundary
|
|
|
|
a.mario.position.X = -(a.mario.position.X) // Wrap around to the right side
|
|
|
|
a.mario.dir.X = -a.mario.dir.X // Reverse direction when hitting left edge
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|