we'll see how this goes with the larger model
build rgb-board / build (push) Failing after 5m16s Details

main
Nathan Wagner 3 weeks ago
parent 9e9084c9e7
commit 3f2af28a9a

@ -6,6 +6,8 @@ import (
"log"
"os"
"math"
"github.com/disintegration/imaging"
)
@ -14,6 +16,9 @@ type Mario struct {
dir image.Point
images map[string]image.Image
updown string
a float64
b float64
angle float64
}
func loadMario(file string) image.Image {
@ -53,20 +58,36 @@ 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
// Ellipse parameters (centered on canvas)
centerX := a.ctx.Width() / 2
centerY := a.ctx.Height() / 2
// Calculate new position using parametric ellipse equations
t := a.mario.angle
marioX := centerX + a.mario.a*math.Cos(t)
marioY := centerY + a.mario.b*math.Sin(t)
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
// Update angle to move along the ellipse
a.mario.angle += 0.1 // Adjust speed as needed
if a.mario.angle >= 2*math.Pi {
a.mario.angle -= 2 * math.Pi
}
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
// Determine horizontal direction (left/right) for image flipping
if math.Sin(t) > 0 {
a.mario.dir.X = -1 // Moving left
} else {
a.mario.dir.X = 1 // Moving right
}
// Determine vertical direction (up/down) for image selection
if math.Cos(t) > 0 {
a.mario.updown = "marioUp" // Moving downward
} else {
a.mario.updown = "marioDown" // Moving upward
}
// Update Mario's position
a.mario.position.X = marioX
a.mario.position.Y = marioY
}

Loading…
Cancel
Save