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" "log"
"os" "os"
"math"
"github.com/disintegration/imaging" "github.com/disintegration/imaging"
) )
@ -14,6 +16,9 @@ type Mario struct {
dir image.Point dir image.Point
images map[string]image.Image images map[string]image.Image
updown string updown string
a float64
b float64
angle float64
} }
func loadMario(file string) image.Image { func loadMario(file string) image.Image {
@ -53,20 +58,36 @@ 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 // Ellipse parameters (centered on canvas)
a.mario.position.Y += 1 * a.mario.dir.Y 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() { // Update angle to move along the ellipse
a.mario.dir.Y = -1 a.mario.angle += 0.1 // Adjust speed as needed
a.mario.updown = "marioUp" if a.mario.angle >= 2*math.Pi {
} else if a.mario.position.Y-a.height < 0 { a.mario.angle -= 2 * math.Pi
a.mario.updown = "marioDown"
a.mario.dir.Y = 1
} }
if a.mario.position.X+a.width > a.ctx.Width() { // Determine horizontal direction (left/right) for image flipping
a.mario.dir.X = -1 if math.Sin(t) > 0 {
} else if a.mario.position.X-a.width < 0 { a.mario.dir.X = -1 // Moving left
a.mario.dir.X = 1 } 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