This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
@@ -54,48 +53,20 @@ func (a *Animation) animateMario() {
|
||||
|
||||
// what mario does every frame
|
||||
func (a *Animation) updateMarioPosition() {
|
||||
/* a.mario.position.X += 1 * a.mario.dir.X
|
||||
a.mario.position.Y += 1 * a.mario.dir.Y
|
||||
a.mario.position.X += 1 * a.mario.dir.X
|
||||
a.mario.position.Y += 1 * a.mario.dir.Y
|
||||
|
||||
if a.mario.position.Y+a.height > a.ctx.Height() {
|
||||
a.mario.dir.Y = -1
|
||||
a.mario.updown = "marioUp"
|
||||
} else if a.mario.position.Y-a.height < 0 {
|
||||
a.mario.updown = "marioDown"
|
||||
a.mario.dir.Y = 1
|
||||
}
|
||||
|
||||
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
|
||||
}*/
|
||||
const (
|
||||
wavelength = 20 // Wavelength of the sine wave
|
||||
amplitude = 4 // Amplitude of the sine wave
|
||||
)
|
||||
|
||||
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.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() {
|
||||
a.mario.position.Y = a.ctx.Height() - a.height // Reset Y position to the top boundary
|
||||
a.mario.dir.Y = -1
|
||||
a.mario.updown = "marioUp"
|
||||
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
|
||||
} else if a.mario.position.Y-a.height < 0 {
|
||||
a.mario.updown = "marioDown"
|
||||
a.mario.dir.Y *= -1 // Reverse direction when hitting top
|
||||
a.mario.dir.Y = 1
|
||||
}
|
||||
|
||||
if a.mario.position.X+a.width > a.ctx.Width() {
|
||||
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
|
||||
a.mario.dir.X = -1
|
||||
} else if a.mario.position.X-a.width < 0 {
|
||||
a.mario.dir.X = 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user