54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package animation
|
|
|
|
import (
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
)
|
|
|
|
type SpriteAnimation interface {
|
|
Draw(frame int32, 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 int32
|
|
length int32
|
|
angle float64
|
|
center *sdl.Point
|
|
flip sdl.RendererFlip
|
|
}
|
|
|
|
func NewEntityAnimation(
|
|
spriteAnimation SpriteAnimation,
|
|
speed int32,
|
|
length int32,
|
|
angle float64,
|
|
center *sdl.Point,
|
|
flip sdl.RendererFlip,
|
|
) *entityAnimation {
|
|
|
|
e := entityAnimation{
|
|
spriteAnimation: spriteAnimation,
|
|
speed: speed,
|
|
length: length,
|
|
angle: angle,
|
|
center: center,
|
|
flip: flip,
|
|
}
|
|
|
|
return &e
|
|
}
|
|
|
|
func (e *entityAnimation) Draw(frame int32, windowPosition *sdl.Point) error {
|
|
return e.spriteAnimation.Draw(frame, windowPosition, e.angle, e.center, e.flip)
|
|
}
|
|
|
|
func (e *entityAnimation) GetSpeed() int32 {
|
|
return e.speed
|
|
}
|
|
|
|
func DefineAnimations() {
|
|
DefinePenguinAnimations()
|
|
}
|