Use fullscreen mode. Fix some linter issues
parent
2e0ac84163
commit
662517d1de
4
go.mod
4
go.mod
|
@ -1,9 +1,9 @@
|
||||||
module git.wisellama.rocks/Project-Ely/project-ely
|
module git.wisellama.rocks/Project-Ely/project-ely
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.wisellama.rocks/Wisellama/gopackagebase v0.0.4
|
git.wisellama.rocks/Wisellama/gopackagebase v0.0.4
|
||||||
git.wisellama.rocks/Wisellama/gosimpleconf v0.1.0
|
git.wisellama.rocks/Wisellama/gosimpleconf v0.1.0
|
||||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20221117130019-ce3c8e83dd6d
|
github.com/gen2brain/raylib-go/raylib v0.0.0-20230413192425-0fdd3be3077b
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -2,5 +2,5 @@ git.wisellama.rocks/Wisellama/gopackagebase v0.0.4 h1:EUj/GqcSLJVm4aedSFaleudXlJ
|
||||||
git.wisellama.rocks/Wisellama/gopackagebase v0.0.4/go.mod h1:0xUyJkT61TTIpekmeApB8U0mVwNqX/6Iz85RKUZQYyU=
|
git.wisellama.rocks/Wisellama/gopackagebase v0.0.4/go.mod h1:0xUyJkT61TTIpekmeApB8U0mVwNqX/6Iz85RKUZQYyU=
|
||||||
git.wisellama.rocks/Wisellama/gosimpleconf v0.1.0 h1:Z2FAzARct8ShV4NSueC/y+PyuSQVcyo4WnW7GoZ9L10=
|
git.wisellama.rocks/Wisellama/gosimpleconf v0.1.0 h1:Z2FAzARct8ShV4NSueC/y+PyuSQVcyo4WnW7GoZ9L10=
|
||||||
git.wisellama.rocks/Wisellama/gosimpleconf v0.1.0/go.mod h1:Gg1vUTBRZD7qcXvdF8L50PsnL9coLt/XbWa5BwSDN/M=
|
git.wisellama.rocks/Wisellama/gosimpleconf v0.1.0/go.mod h1:Gg1vUTBRZD7qcXvdF8L50PsnL9coLt/XbWa5BwSDN/M=
|
||||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20221117130019-ce3c8e83dd6d h1:X+URitXeDGTT5Ng5LhEG0DPdHq8DDL16dWnJMxgGj+8=
|
github.com/gen2brain/raylib-go/raylib v0.0.0-20230413192425-0fdd3be3077b h1:a6MhRr2wZWGfWVu+hrnz+qkW/lGZzFPggpFJA8Zzj0I=
|
||||||
github.com/gen2brain/raylib-go/raylib v0.0.0-20221117130019-ce3c8e83dd6d/go.mod h1:+NbsqGlEQqGqrsgJFF5Yj2dkvn0ML2SQb8RqM2hJsPU=
|
github.com/gen2brain/raylib-go/raylib v0.0.0-20230413192425-0fdd3be3077b/go.mod h1:AwtGA3aTtYdezNxEVbfchaLw/z+CuRDh2Mlxy0FbBro=
|
||||||
|
|
|
@ -5,14 +5,14 @@ var AnimationMap map[int]entityAnimation
|
||||||
|
|
||||||
// Enum containing IDs of all animations that exist to make them easy to reference.
|
// Enum containing IDs of all animations that exist to make them easy to reference.
|
||||||
const (
|
const (
|
||||||
PENGUIN_WALK_RIGHT int = iota
|
PenguinWalkRight int = iota
|
||||||
PENGUIN_WALK_LEFT
|
PenguinWalkLeft
|
||||||
PENGUIN_WALK_UP
|
PenguinWalkUp
|
||||||
PENGUIN_WALK_DOWN
|
PenguinWalkDown
|
||||||
PENGUIN_STATIONARY_RIGHT
|
PenguinStationaryRight
|
||||||
PENGUIN_STATIONARY_LEFT
|
PenguinStationaryLeft
|
||||||
PENGUIN_STATIONARY_UP
|
PenguinStationaryUp
|
||||||
PENGUIN_STATIONARY_DOWN
|
PenguinStationaryDown
|
||||||
)
|
)
|
||||||
|
|
||||||
func DefineAnimations() {
|
func DefineAnimations() {
|
||||||
|
|
|
@ -16,10 +16,10 @@ type SpriteAnimation interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
FLIP_NONE = rl.Vector2{X: 0, Y: 0}
|
FlipNone = rl.Vector2{X: 0, Y: 0}
|
||||||
FLIP_HORIZONTAL = rl.Vector2{X: 1, Y: 0}
|
FlipHorizontal = rl.Vector2{X: 1, Y: 0}
|
||||||
FLIP_VERTICAL = rl.Vector2{X: 0, Y: 1}
|
FlipVertical = rl.Vector2{X: 0, Y: 1}
|
||||||
FLIP_BOTH = rl.Vector2{X: 1, Y: 1}
|
FlipBoth = rl.Vector2{X: 1, Y: 1}
|
||||||
)
|
)
|
||||||
|
|
||||||
// An entityAnimation will take a SpriteAnimation and may manipulate it somehow (e.g. flipped for walking the other direction)
|
// An entityAnimation will take a SpriteAnimation and may manipulate it somehow (e.g. flipped for walking the other direction)
|
||||||
|
|
|
@ -8,23 +8,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PENGUIN_DEFAULT = PENGUIN_STATIONARY_RIGHT
|
PenguinDefault = PenguinStationaryRight
|
||||||
)
|
)
|
||||||
|
|
||||||
var penguinAnimations []int
|
var penguinAnimations []int
|
||||||
|
|
||||||
func DefinePenguinAnimations() {
|
func DefinePenguinAnimations() {
|
||||||
filename := sprite.DELILAHWALKING
|
filename := sprite.DelilahWalking
|
||||||
|
|
||||||
penguinAnimations = make([]int, 0)
|
penguinAnimations = make([]int, 0)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_RIGHT)
|
penguinAnimations = append(penguinAnimations, PenguinWalkRight)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_LEFT)
|
penguinAnimations = append(penguinAnimations, PenguinWalkLeft)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_UP)
|
penguinAnimations = append(penguinAnimations, PenguinWalkUp)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_WALK_DOWN)
|
penguinAnimations = append(penguinAnimations, PenguinWalkDown)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_RIGHT)
|
penguinAnimations = append(penguinAnimations, PenguinStationaryRight)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_LEFT)
|
penguinAnimations = append(penguinAnimations, PenguinStationaryLeft)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_UP)
|
penguinAnimations = append(penguinAnimations, PenguinStationaryUp)
|
||||||
penguinAnimations = append(penguinAnimations, PENGUIN_STATIONARY_DOWN)
|
penguinAnimations = append(penguinAnimations, PenguinStationaryDown)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dimensions rl.Vector2
|
dimensions rl.Vector2
|
||||||
|
@ -44,38 +44,38 @@ func DefinePenguinAnimations() {
|
||||||
border = 1 // optional border around each sprite
|
border = 1 // optional border around each sprite
|
||||||
center = getCenter(dimensions) // center is for rotation, nil will default to w/2 h/2
|
center = getCenter(dimensions) // center is for rotation, nil will default to w/2 h/2
|
||||||
walkRight := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
walkRight := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
||||||
AnimationMap[PENGUIN_WALK_RIGHT] = NewEntityAnimation(walkRight, speed, length, 0, center, FLIP_NONE)
|
AnimationMap[PenguinWalkRight] = NewEntityAnimation(walkRight, speed, length, 0, center, FlipNone)
|
||||||
|
|
||||||
// Walking Left is just that flipped.
|
// Walking Left is just that flipped.
|
||||||
AnimationMap[PENGUIN_WALK_LEFT] = NewEntityAnimation(walkRight, speed, length, 0, center, FLIP_HORIZONTAL)
|
AnimationMap[PenguinWalkLeft] = NewEntityAnimation(walkRight, speed, length, 0, center, FlipHorizontal)
|
||||||
|
|
||||||
// Stationary Right/Left is just the first frame.
|
// Stationary Right/Left is just the first frame.
|
||||||
length = 1
|
length = 1
|
||||||
stationaryRight := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
stationaryRight := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
||||||
AnimationMap[PENGUIN_STATIONARY_RIGHT] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FLIP_NONE)
|
AnimationMap[PenguinStationaryRight] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FlipNone)
|
||||||
AnimationMap[PENGUIN_STATIONARY_LEFT] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FLIP_HORIZONTAL)
|
AnimationMap[PenguinStationaryLeft] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FlipHorizontal)
|
||||||
|
|
||||||
// Walk Up
|
// Walk Up
|
||||||
length = 4
|
length = 4
|
||||||
offset = rl.Vector2{X: 0, Y: 3}
|
offset = rl.Vector2{X: 0, Y: 3}
|
||||||
walkUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
walkUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
||||||
AnimationMap[PENGUIN_WALK_UP] = NewEntityAnimation(walkUp, speed, length, 0, center, FLIP_NONE)
|
AnimationMap[PenguinWalkUp] = NewEntityAnimation(walkUp, speed, length, 0, center, FlipNone)
|
||||||
|
|
||||||
// Stationary Up
|
// Stationary Up
|
||||||
length = 1
|
length = 1
|
||||||
stationaryUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
stationaryUp := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
||||||
AnimationMap[PENGUIN_STATIONARY_UP] = NewEntityAnimation(stationaryUp, speed, length, 0, center, FLIP_NONE)
|
AnimationMap[PenguinStationaryUp] = NewEntityAnimation(stationaryUp, speed, length, 0, center, FlipNone)
|
||||||
|
|
||||||
// Walk Down
|
// Walk Down
|
||||||
length = 4
|
length = 4
|
||||||
offset = rl.Vector2{X: 0, Y: 0}
|
offset = rl.Vector2{X: 0, Y: 0}
|
||||||
walkDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
walkDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
||||||
AnimationMap[PENGUIN_WALK_DOWN] = NewEntityAnimation(walkDown, speed, length, 0, center, FLIP_NONE)
|
AnimationMap[PenguinWalkDown] = NewEntityAnimation(walkDown, speed, length, 0, center, FlipNone)
|
||||||
|
|
||||||
// Stationary Down
|
// Stationary Down
|
||||||
length = 1
|
length = 1
|
||||||
stationaryDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
stationaryDown := sprite.NewAnimation(filename, dimensions, offset, length, border)
|
||||||
AnimationMap[PENGUIN_STATIONARY_DOWN] = NewEntityAnimation(stationaryDown, speed, length, 0, center, FLIP_NONE)
|
AnimationMap[PenguinStationaryDown] = NewEntityAnimation(stationaryDown, speed, length, 0, center, FlipNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RandomPenguinAnimation() int {
|
func RandomPenguinAnimation() int {
|
||||||
|
|
|
@ -16,35 +16,36 @@ type AnimationTracker interface {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// These line up with the VEC_DIRECTIONS slice
|
// These line up with the VEC_DIRECTIONS slice
|
||||||
DIR_LEFT int = iota
|
|
||||||
DIR_RIGHT
|
DirLeft int = iota
|
||||||
DIR_UP
|
DirRight
|
||||||
DIR_DOWN
|
DirUp
|
||||||
|
DirDown
|
||||||
)
|
)
|
||||||
|
|
||||||
// The following are axis direction vectors based on world coordinates.
|
// The following are axis direction vectors based on world coordinates.
|
||||||
// UP/DOWN is intentionally UP = positive (which is different from window coordinates)
|
// UP/DOWN is intentionally UP = positive (which is different from window coordinates)
|
||||||
var (
|
var (
|
||||||
VEC_LEFT = rl.Vector2{X: -1, Y: 0}
|
VecLeft = rl.Vector2{X: -1, Y: 0}
|
||||||
VEC_RIGHT = rl.Vector2{X: 1, Y: 0}
|
VecRight = rl.Vector2{X: 1, Y: 0}
|
||||||
VEC_UP = rl.Vector2{X: 0, Y: 1}
|
VecUp = rl.Vector2{X: 0, Y: 1}
|
||||||
VEC_DOWN = rl.Vector2{X: 0, Y: -1}
|
VecDown = rl.Vector2{X: 0, Y: -1}
|
||||||
|
|
||||||
VEC_DIRECTIONS = []rl.Vector2{
|
VecDirections = []rl.Vector2{
|
||||||
// Prefer left/right animations by checking them first in the list
|
// Prefer left/right animations by checking them first in the list
|
||||||
VEC_LEFT,
|
VecLeft,
|
||||||
VEC_RIGHT,
|
VecRight,
|
||||||
VEC_UP,
|
VecUp,
|
||||||
VEC_DOWN,
|
VecDown,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func determineClosestDirection(velocity rl.Vector2) int {
|
func determineClosestDirection(velocity rl.Vector2) int {
|
||||||
closest := DIR_RIGHT
|
closest := DirRight
|
||||||
max := float32(0)
|
max := float32(0)
|
||||||
buffer := float32(0.5) // This buffer lets us stick to the left/right animations for diagonal movement
|
buffer := float32(0.5) // This buffer lets us stick to the left/right animations for diagonal movement
|
||||||
|
|
||||||
for i, dir := range VEC_DIRECTIONS {
|
for i, dir := range VecDirections {
|
||||||
dot := rl.Vector2DotProduct(velocity, dir)
|
dot := rl.Vector2DotProduct(velocity, dir)
|
||||||
if dot > max+buffer {
|
if dot > max+buffer {
|
||||||
max = dot
|
max = dot
|
||||||
|
|
|
@ -20,7 +20,7 @@ type penguin struct {
|
||||||
func NewPenguin() *penguin {
|
func NewPenguin() *penguin {
|
||||||
object := physics.NewObject()
|
object := physics.NewObject()
|
||||||
anim := animation.NewAnimationTracker()
|
anim := animation.NewAnimationTracker()
|
||||||
anim.SetAnimation(animation.PENGUIN_DEFAULT)
|
anim.SetAnimation(animation.PenguinDefault)
|
||||||
|
|
||||||
return &penguin{
|
return &penguin{
|
||||||
animation: anim,
|
animation: anim,
|
||||||
|
@ -75,17 +75,17 @@ func (p *penguin) SetMoveAnimation() {
|
||||||
// Stay facing whatever direction we were facing
|
// Stay facing whatever direction we were facing
|
||||||
direction := p.direction
|
direction := p.direction
|
||||||
switch direction {
|
switch direction {
|
||||||
case DIR_LEFT:
|
case DirLeft:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_LEFT)
|
p.animation.SetAnimation(animation.PenguinStationaryLeft)
|
||||||
case DIR_RIGHT:
|
case DirRight:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_RIGHT)
|
p.animation.SetAnimation(animation.PenguinStationaryRight)
|
||||||
case DIR_UP:
|
case DirUp:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_UP)
|
p.animation.SetAnimation(animation.PenguinStationaryUp)
|
||||||
case DIR_DOWN:
|
case DirDown:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_DOWN)
|
p.animation.SetAnimation(animation.PenguinStationaryDown)
|
||||||
default:
|
default:
|
||||||
log.Printf("unknown direction: %v", direction)
|
log.Printf("unknown direction: %v", direction)
|
||||||
p.animation.SetAnimation(animation.PENGUIN_DEFAULT)
|
p.animation.SetAnimation(animation.PenguinDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,17 +94,17 @@ func (p *penguin) SetMoveAnimation() {
|
||||||
p.direction = direction
|
p.direction = direction
|
||||||
|
|
||||||
switch direction {
|
switch direction {
|
||||||
case DIR_LEFT:
|
case DirLeft:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_WALK_LEFT)
|
p.animation.SetAnimation(animation.PenguinWalkLeft)
|
||||||
case DIR_RIGHT:
|
case DirRight:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_WALK_RIGHT)
|
p.animation.SetAnimation(animation.PenguinWalkRight)
|
||||||
case DIR_UP:
|
case DirUp:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_WALK_UP)
|
p.animation.SetAnimation(animation.PenguinWalkUp)
|
||||||
case DIR_DOWN:
|
case DirDown:
|
||||||
p.animation.SetAnimation(animation.PENGUIN_WALK_DOWN)
|
p.animation.SetAnimation(animation.PenguinWalkDown)
|
||||||
default:
|
default:
|
||||||
log.Printf("unknown direction: %v", direction)
|
log.Printf("unknown direction: %v", direction)
|
||||||
p.animation.SetAnimation(animation.PENGUIN_DEFAULT)
|
p.animation.SetAnimation(animation.PenguinDefault)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,12 @@ import (
|
||||||
rl "github.com/gen2brain/raylib-go/raylib"
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Drawables can be rendered with OpenGL. See the 'entity' and 'animation' packages.
|
// Drawable can be rendered with OpenGL. See the 'entity' and 'animation' packages.
|
||||||
type Drawable interface {
|
type Drawable interface {
|
||||||
Draw() error
|
Draw() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objects can have physical interactions. See the 'entity' and 'physics' packages.
|
// Object can have physical interactions. See the 'entity' and 'physics' packages.
|
||||||
type Object interface {
|
type Object interface {
|
||||||
Update() error
|
Update() error
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,11 @@ func Run(ctx context.Context, configMap gosimpleconf.ConfigMap) error {
|
||||||
|
|
||||||
// Initialize the RayLib window
|
// Initialize the RayLib window
|
||||||
channels.RL.Do(func() {
|
channels.RL.Do(func() {
|
||||||
rl.InitWindow(800, 600, windowTitle)
|
monitor := rl.GetCurrentMonitor()
|
||||||
|
windowWidth := int32(rl.GetMonitorWidth(monitor))
|
||||||
|
windowHeight := int32(rl.GetMonitorHeight(monitor))
|
||||||
|
rl.InitWindow(windowWidth, windowHeight, windowTitle)
|
||||||
|
rl.ToggleFullscreen()
|
||||||
rl.SetTargetFPS(framerate)
|
rl.SetTargetFPS(framerate)
|
||||||
})
|
})
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package sprite
|
package sprite
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PENGUIN = "assets/images/penguin.png"
|
Penguin = "assets/images/penguin.png"
|
||||||
PERCYWALKING = "assets/images/percywalking.png"
|
PercyWalking = "assets/images/percywalking.png"
|
||||||
PLATFORMER_FOREST_CHARACTERS = "assets/images/a-platformer-in-the-forest/characters.png"
|
PlatformerForestCharacters = "assets/images/a-platformer-in-the-forest/characters.png"
|
||||||
DELILAHWALKING = "assets/images/Delilah_walking.png"
|
DelilahWalking = "assets/images/Delilah_walking.png"
|
||||||
KINGWALKING = "assets/images/King_walking.png"
|
KingWalking = "assets/images/King_walking.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
var SPRITE_FILE_LIST []string = []string{
|
var SpriteFileList []string = []string{
|
||||||
PENGUIN,
|
Penguin,
|
||||||
PERCYWALKING,
|
PercyWalking,
|
||||||
PLATFORMER_FOREST_CHARACTERS,
|
PlatformerForestCharacters,
|
||||||
DELILAHWALKING,
|
DelilahWalking,
|
||||||
KINGWALKING,
|
KingWalking,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ var (
|
||||||
func InitSpriteCache() {
|
func InitSpriteCache() {
|
||||||
spriteCache = make(map[string]*spritesheet)
|
spriteCache = make(map[string]*spritesheet)
|
||||||
|
|
||||||
for _, filename := range SPRITE_FILE_LIST {
|
for _, filename := range SpriteFileList {
|
||||||
s := NewSprite(filename)
|
s := NewSprite(filename)
|
||||||
spriteCache[filename] = s
|
spriteCache[filename] = s
|
||||||
}
|
}
|
||||||
|
|
4
main.go
4
main.go
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CONFIG_FILE = "project-ely.conf"
|
configFile = "project-ely.conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{
|
var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{
|
||||||
|
@ -24,7 +24,7 @@ var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
baseConfig, err := gopackagebase.Initialize(CONFIG_FILE, defaultConfig)
|
baseConfig, err := gopackagebase.Initialize(configFile, defaultConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error initializing: %v", err)
|
log.Fatalf("error initializing: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue