Nathan Wagner 2 months ago
parent 8e92059e54
commit 843a009343

@ -84,16 +84,18 @@ func (a *Animation) updateMarioPosition() {
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.updown = "marioUp"
a.mario.dir.Y = -1 // Reverse direction when hitting bottom
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 // Reverse direction when hitting top
a.mario.dir.Y *= -1 // Reverse direction when hitting top
}
if a.mario.position.X+a.width > a.ctx.Width() {
a.mario.position.X -= (a.mario.position.X + a.width - a.ctx.Width()) // Wrap around to the left side
a.mario.position.X = a.ctx.Width() - (a.mario.position.X + a.width - a.ctx.Width()) // Wrap around to the left side
a.mario.dir.X *= -1 // Reverse X direction
} else if a.mario.position.X < 0 {
a.mario.position.X = -(a.mario.position.X) // Wrap around to the right side
a.mario.dir.X *= -1 // Reverse X direction
}
}

Loading…
Cancel
Save