86 lines
3.0 KiB
Go
86 lines
3.0 KiB
Go
package animation
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"git.wisellama.rocks/Project-Ely/project-ely/internal/sprite"
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
const (
|
|
PENGUIN_DEFAULT = PENGUIN_STATIONARY_RIGHT
|
|
)
|
|
|
|
var penguinAnimations []int
|
|
|
|
func DefinePenguinAnimations() {
|
|
filename := sprite.DELILAHWALKING
|
|
|
|
penguinAnimations = make([]int, 0)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_RIGHT)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_LEFT)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_UP)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_DOWN)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_RIGHT)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_LEFT)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_UP)
|
|
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_DOWN)
|
|
|
|
var (
|
|
dimensions rl.Vector2
|
|
offset rl.Vector2
|
|
center rl.Vector2
|
|
length int
|
|
speed int
|
|
border int
|
|
)
|
|
|
|
dimensions = rl.Vector2{X: 13, Y: 17}
|
|
|
|
// Walking Right is in the spritesheet.
|
|
speed = 5
|
|
offset = rl.Vector2{X: 0, Y: 1}
|
|
length = 5
|
|
border = 1 // optional border around each sprite
|
|
center = getCenter(dimensions) // center is for rotation, nil will default to w/2 h/2
|
|
walkRight := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
AnimationMap[PENGUIN_WALK_RIGHT] = NewEntityAnimation(walkRight, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Walking Left is just that flipped.
|
|
AnimationMap[PENGUIN_WALK_LEFT] = NewEntityAnimation(walkRight, speed, length, 0, center, FLIP_HORIZONTAL)
|
|
|
|
// Stationary Right/Left is just the first frame.
|
|
length = 1
|
|
stationaryRight := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
AnimationMap[PENGUIN_STATIONARY_RIGHT] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FLIP_NONE)
|
|
AnimationMap[PENGUIN_STATIONARY_LEFT] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FLIP_HORIZONTAL)
|
|
|
|
// Walk Up
|
|
length = 4
|
|
offset = rl.Vector2{X: 0, Y: 3}
|
|
walkUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
AnimationMap[PENGUIN_WALK_UP] = NewEntityAnimation(walkUp, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Stationary Up
|
|
length = 1
|
|
stationaryUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
AnimationMap[PENGUIN_STATIONARY_UP] = NewEntityAnimation(stationaryUp, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Walk Down
|
|
length = 4
|
|
offset = rl.Vector2{X: 0, Y: 0}
|
|
walkDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
AnimationMap[PENGUIN_WALK_DOWN] = NewEntityAnimation(walkDown, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Stationary Down
|
|
length = 1
|
|
stationaryDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
AnimationMap[PENGUIN_STATIONARY_DOWN] = NewEntityAnimation(stationaryDown, speed, length, 0, center, FLIP_NONE)
|
|
}
|
|
|
|
func RandomPenguinAnimation() int {
|
|
n := len(penguinAnimations)
|
|
i := rand.Intn(n)
|
|
return penguinAnimations[i]
|
|
}
|