|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
"image"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"image/color"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
@ -54,7 +53,7 @@ func (a *Animation) animateMario() {
|
|
|
|
|
|
|
|
|
|
|
|
// what mario does every frame
|
|
|
|
// what mario does every frame
|
|
|
|
func (a *Animation) updateMarioPosition() {
|
|
|
|
func (a *Animation) updateMarioPosition() {
|
|
|
|
/* a.mario.position.X += 1 * a.mario.dir.X
|
|
|
|
a.mario.position.X += 1 * a.mario.dir.X
|
|
|
|
a.mario.position.Y += 1 * a.mario.dir.Y
|
|
|
|
a.mario.position.Y += 1 * a.mario.dir.Y
|
|
|
|
|
|
|
|
|
|
|
|
if a.mario.position.Y+a.height > a.ctx.Height() {
|
|
|
|
if a.mario.position.Y+a.height > a.ctx.Height() {
|
|
|
@ -69,33 +68,5 @@ func (a *Animation) updateMarioPosition() {
|
|
|
|
a.mario.dir.X = -1
|
|
|
|
a.mario.dir.X = -1
|
|
|
|
} else if a.mario.position.X-a.width < 0 {
|
|
|
|
} else if a.mario.position.X-a.width < 0 {
|
|
|
|
a.mario.dir.X = 1
|
|
|
|
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.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
|
|
|
|
|
|
|
|
a.mario.updown = "marioDown"
|
|
|
|
|
|
|
|
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.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
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|