81 lines
2.6 KiB
Go
81 lines
2.6 KiB
Go
package animation
|
|
|
|
import (
|
|
"git.wisellama.rocks/Project-Ely/project-ely/internal/game/sprite"
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
|
)
|
|
|
|
var PenguinAnimations map[int]entityAnimation
|
|
|
|
const (
|
|
PENGUIN_WALK_RIGHT int = iota
|
|
PENGUIN_WALK_LEFT
|
|
PENGUIN_WALK_UP
|
|
PENGUIN_WALK_DOWN
|
|
PENGUIN_STATIONARY_RIGHT
|
|
PENGUIN_STATIONARY_LEFT
|
|
PENGUIN_STATIONARY_UP
|
|
PENGUIN_STATIONARY_DOWN
|
|
)
|
|
|
|
const (
|
|
PENGUIN_NUM_ANIMS = 8
|
|
PENGUIN_DEFAULT = PENGUIN_STATIONARY_RIGHT
|
|
)
|
|
|
|
func DefinePenguinAnimations() {
|
|
filename := sprite.DELILAHWALKING
|
|
|
|
var (
|
|
dimensions rl.Vector2
|
|
offset rl.Vector2
|
|
center rl.Vector2
|
|
length int
|
|
speed int
|
|
border int
|
|
)
|
|
|
|
dimensions = rl.Vector2{X: 13, Y: 17}
|
|
PenguinAnimations = make(map[int]entityAnimation)
|
|
|
|
// 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)
|
|
PenguinAnimations[PENGUIN_WALK_RIGHT] = NewEntityAnimation(walkRight, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Walking Left is just that flipped.
|
|
PenguinAnimations[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)
|
|
PenguinAnimations[PENGUIN_STATIONARY_RIGHT] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FLIP_NONE)
|
|
PenguinAnimations[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)
|
|
PenguinAnimations[PENGUIN_WALK_UP] = NewEntityAnimation(walkUp, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Stationary Up
|
|
length = 1
|
|
stationaryUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
PenguinAnimations[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)
|
|
PenguinAnimations[PENGUIN_WALK_DOWN] = NewEntityAnimation(walkDown, speed, length, 0, center, FLIP_NONE)
|
|
|
|
// Stationary Down
|
|
length = 1
|
|
stationaryDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
|
PenguinAnimations[PENGUIN_STATIONARY_DOWN] = NewEntityAnimation(stationaryDown, speed, length, 0, center, FLIP_NONE)
|
|
}
|