59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package animation
|
|
|
|
import (
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
)
|
|
|
|
type SpriteAnimation interface {
|
|
Draw(frame int, worldPosition sdl.Point, angle float64, center sdl.Point, flip sdl.RendererFlip) error
|
|
}
|
|
|
|
// An entityAnimation will take a SpriteAnimation and may manipulate it somehow (e.g. flipped for walking the other direction)
|
|
// This way you may cut down the actual number of pictures needed to define all the different animations.
|
|
type entityAnimation struct {
|
|
spriteAnimation SpriteAnimation
|
|
speed int
|
|
length int
|
|
angle float64
|
|
center sdl.Point
|
|
flip sdl.RendererFlip
|
|
}
|
|
|
|
func NewEntityAnimation(
|
|
spriteAnimation SpriteAnimation,
|
|
speed int,
|
|
length int,
|
|
angle float64,
|
|
center sdl.Point,
|
|
flip sdl.RendererFlip,
|
|
) entityAnimation {
|
|
|
|
return entityAnimation{
|
|
spriteAnimation: spriteAnimation,
|
|
speed: speed,
|
|
length: length,
|
|
angle: angle,
|
|
center: center,
|
|
flip: flip,
|
|
}
|
|
}
|
|
|
|
func (e entityAnimation) Draw(frame int, windowPosition sdl.Point) error {
|
|
return e.spriteAnimation.Draw(frame, windowPosition, e.angle, e.center, e.flip)
|
|
}
|
|
|
|
func (e entityAnimation) GetSpeed() int {
|
|
return e.speed
|
|
}
|
|
|
|
func DefineAnimations() {
|
|
DefinePenguinAnimations()
|
|
}
|
|
|
|
func getCenter(dimensions sdl.Point) sdl.Point {
|
|
x := dimensions.X / 2
|
|
y := dimensions.Y / 2
|
|
|
|
return sdl.Point{X: x, Y: y}
|
|
}
|