Compare commits

...

2 Commits

Author SHA1 Message Date
856471ec7d revert
All checks were successful
build rgb-board / build (push) Successful in 13m54s
2025-05-18 03:21:16 +00:00
843a009343 :wq 2025-05-02 01:59:16 +00:00

View File

@@ -4,7 +4,6 @@ import (
"image"
"image/color"
"log"
"math"
"os"
"github.com/disintegration/imaging"
@@ -54,46 +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.mario.position.X + a.width - a.ctx.Width()) // Wrap around to the left side
} 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
} else if a.mario.position.X-a.width < 0 {
a.mario.dir.X = 1
}
}