|
|
|
@ -56,38 +56,37 @@ func (a *Animation) animateMario() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// what mario does every frame
|
|
|
|
|
func (a *Animation) updateMarioPosition() {
|
|
|
|
|
// 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 := int(float64(centerX) + math.Round(a.mario.a*math.Cos(t)))
|
|
|
|
|
marioY := int(float64(centerY) + math.Round(a.mario.b*math.Sin(t)))
|
|
|
|
|
marioX := int(math.Round(float64(a.mario.a * math.Cos(t))))
|
|
|
|
|
marioY := int(math.Round(float64(a.mario.b * math.Sin(t))))
|
|
|
|
|
|
|
|
|
|
// Adjust position relative to the center of the panel
|
|
|
|
|
marioX += centerX
|
|
|
|
|
marioY += centerY
|
|
|
|
|
|
|
|
|
|
a.mario.position.X = marioX
|
|
|
|
|
a.mario.position.Y = marioY
|
|
|
|
|
|
|
|
|
|
// Update angle to move along the ellipse
|
|
|
|
|
a.mario.angle += 0.1 // Adjust speed as needed
|
|
|
|
|
a.mario.angle += 0.1
|
|
|
|
|
if a.mario.angle >= 2*math.Pi {
|
|
|
|
|
a.mario.angle -= 2 * math.Pi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine horizontal direction (left/right) for image flipping
|
|
|
|
|
// Direction logic
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|