|
|
|
@ -77,20 +77,24 @@ func (a *Animation) updateMarioPosition() {
|
|
|
|
|
|
|
|
|
|
currentTime := float64(a.ctx.Width()) / wavelength // Calculate current time based on position
|
|
|
|
|
|
|
|
|
|
a.mario.position.X += int(amplitude*math.Sin(2*math.Pi*currentTime/wavelength)) + 1*a.mario.dir.X
|
|
|
|
|
a.mario.position.Y += 1 * a.mario.dir.Y
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
if a.mario.position.Y+a.height > a.ctx.Height() {
|
|
|
|
|
a.mario.dir.Y = -1
|
|
|
|
|
a.mario.position.Y = a.ctx.Height() - a.height // Reset Y position to the top boundary
|
|
|
|
|
a.mario.updown = "marioUp"
|
|
|
|
|
} else if a.mario.position.Y-a.height < 0 {
|
|
|
|
|
a.mario.dir.Y = -1 // Reverse direction when hitting bottom
|
|
|
|
|
} else if a.mario.position.Y < 0 {
|
|
|
|
|
a.mario.position.Y = 0 // Reset Y position to the bottom boundary
|
|
|
|
|
a.mario.updown = "marioDown"
|
|
|
|
|
a.mario.dir.Y = 1
|
|
|
|
|
a.mario.dir.Y = 1 // Reverse direction when hitting top
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if a.mario.position.X+a.width > a.ctx.Width() {
|
|
|
|
|
a.mario.dir.X = -1
|
|
|
|
|
} else if a.mario.position.X-a.width < 0 {
|
|
|
|
|
a.mario.dir.X = 1
|
|
|
|
|
a.mario.position.X = a.ctx.Width() - a.width // Reset X position to the left boundary
|
|
|
|
|
a.mario.dir.X = -a.mario.dir.X // Reverse direction when hitting right edge
|
|
|
|
|
} else if a.mario.position.X < 0 {
|
|
|
|
|
a.mario.position.X = 0 // Reset X position to the right boundary
|
|
|
|
|
a.mario.dir.X = -a.mario.dir.X // Reverse direction when hitting left edge
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|