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
|
||||
|
||||
go 1.18
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
git.wisellama.rocks/Wisellama/gopackagebase v0.0.4
|
||||
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/gosimpleconf v0.1.0 h1:Z2FAzARct8ShV4NSueC/y+PyuSQVcyo4WnW7GoZ9L10=
|
||||
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-20221117130019-ce3c8e83dd6d/go.mod h1:+NbsqGlEQqGqrsgJFF5Yj2dkvn0ML2SQb8RqM2hJsPU=
|
||||
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-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.
|
||||
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
|
||||
PenguinWalkRight int = iota
|
||||
PenguinWalkLeft
|
||||
PenguinWalkUp
|
||||
PenguinWalkDown
|
||||
PenguinStationaryRight
|
||||
PenguinStationaryLeft
|
||||
PenguinStationaryUp
|
||||
PenguinStationaryDown
|
||||
)
|
||||
|
||||
func DefineAnimations() {
|
||||
|
|
|
@ -16,10 +16,10 @@ type SpriteAnimation interface {
|
|||
}
|
||||
|
||||
var (
|
||||
FLIP_NONE = rl.Vector2{X: 0, Y: 0}
|
||||
FLIP_HORIZONTAL = rl.Vector2{X: 1, Y: 0}
|
||||
FLIP_VERTICAL = rl.Vector2{X: 0, Y: 1}
|
||||
FLIP_BOTH = rl.Vector2{X: 1, Y: 1}
|
||||
FlipNone = rl.Vector2{X: 0, Y: 0}
|
||||
FlipHorizontal = rl.Vector2{X: 1, Y: 0}
|
||||
FlipVertical = rl.Vector2{X: 0, 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)
|
||||
|
|
|
@ -8,23 +8,23 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
PENGUIN_DEFAULT = PENGUIN_STATIONARY_RIGHT
|
||||
PenguinDefault = PenguinStationaryRight
|
||||
)
|
||||
|
||||
var penguinAnimations []int
|
||||
|
||||
func DefinePenguinAnimations() {
|
||||
filename := sprite.DELILAHWALKING
|
||||
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)
|
||||
penguinAnimations = append(penguinAnimations, PenguinWalkRight)
|
||||
penguinAnimations = append(penguinAnimations, PenguinWalkLeft)
|
||||
penguinAnimations = append(penguinAnimations, PenguinWalkUp)
|
||||
penguinAnimations = append(penguinAnimations, PenguinWalkDown)
|
||||
penguinAnimations = append(penguinAnimations, PenguinStationaryRight)
|
||||
penguinAnimations = append(penguinAnimations, PenguinStationaryLeft)
|
||||
penguinAnimations = append(penguinAnimations, PenguinStationaryUp)
|
||||
penguinAnimations = append(penguinAnimations, PenguinStationaryDown)
|
||||
|
||||
var (
|
||||
dimensions rl.Vector2
|
||||
|
@ -44,38 +44,38 @@ func DefinePenguinAnimations() {
|
|||
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)
|
||||
AnimationMap[PenguinWalkRight] = NewEntityAnimation(walkRight, speed, length, 0, center, FlipNone)
|
||||
|
||||
// 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.
|
||||
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)
|
||||
AnimationMap[PenguinStationaryRight] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FlipNone)
|
||||
AnimationMap[PenguinStationaryLeft] = NewEntityAnimation(stationaryRight, speed, length, 0, center, FlipHorizontal)
|
||||
|
||||
// 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)
|
||||
AnimationMap[PenguinWalkUp] = NewEntityAnimation(walkUp, speed, length, 0, center, FlipNone)
|
||||
|
||||
// Stationary Up
|
||||
length = 1
|
||||
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
|
||||
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)
|
||||
AnimationMap[PenguinWalkDown] = NewEntityAnimation(walkDown, speed, length, 0, center, FlipNone)
|
||||
|
||||
// Stationary Down
|
||||
length = 1
|
||||
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 {
|
||||
|
|
|
@ -16,35 +16,36 @@ type AnimationTracker interface {
|
|||
|
||||
const (
|
||||
// These line up with the VEC_DIRECTIONS slice
|
||||
DIR_LEFT int = iota
|
||||
DIR_RIGHT
|
||||
DIR_UP
|
||||
DIR_DOWN
|
||||
|
||||
DirLeft int = iota
|
||||
DirRight
|
||||
DirUp
|
||||
DirDown
|
||||
)
|
||||
|
||||
// The following are axis direction vectors based on world coordinates.
|
||||
// UP/DOWN is intentionally UP = positive (which is different from window coordinates)
|
||||
var (
|
||||
VEC_LEFT = rl.Vector2{X: -1, Y: 0}
|
||||
VEC_RIGHT = rl.Vector2{X: 1, Y: 0}
|
||||
VEC_UP = rl.Vector2{X: 0, Y: 1}
|
||||
VEC_DOWN = rl.Vector2{X: 0, Y: -1}
|
||||
VecLeft = rl.Vector2{X: -1, Y: 0}
|
||||
VecRight = rl.Vector2{X: 1, Y: 0}
|
||||
VecUp = 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
|
||||
VEC_LEFT,
|
||||
VEC_RIGHT,
|
||||
VEC_UP,
|
||||
VEC_DOWN,
|
||||
VecLeft,
|
||||
VecRight,
|
||||
VecUp,
|
||||
VecDown,
|
||||
}
|
||||
)
|
||||
|
||||
func determineClosestDirection(velocity rl.Vector2) int {
|
||||
closest := DIR_RIGHT
|
||||
closest := DirRight
|
||||
max := float32(0)
|
||||
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)
|
||||
if dot > max+buffer {
|
||||
max = dot
|
||||
|
|
|
@ -20,7 +20,7 @@ type penguin struct {
|
|||
func NewPenguin() *penguin {
|
||||
object := physics.NewObject()
|
||||
anim := animation.NewAnimationTracker()
|
||||
anim.SetAnimation(animation.PENGUIN_DEFAULT)
|
||||
anim.SetAnimation(animation.PenguinDefault)
|
||||
|
||||
return &penguin{
|
||||
animation: anim,
|
||||
|
@ -75,17 +75,17 @@ func (p *penguin) SetMoveAnimation() {
|
|||
// Stay facing whatever direction we were facing
|
||||
direction := p.direction
|
||||
switch direction {
|
||||
case DIR_LEFT:
|
||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_LEFT)
|
||||
case DIR_RIGHT:
|
||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_RIGHT)
|
||||
case DIR_UP:
|
||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_UP)
|
||||
case DIR_DOWN:
|
||||
p.animation.SetAnimation(animation.PENGUIN_STATIONARY_DOWN)
|
||||
case DirLeft:
|
||||
p.animation.SetAnimation(animation.PenguinStationaryLeft)
|
||||
case DirRight:
|
||||
p.animation.SetAnimation(animation.PenguinStationaryRight)
|
||||
case DirUp:
|
||||
p.animation.SetAnimation(animation.PenguinStationaryUp)
|
||||
case DirDown:
|
||||
p.animation.SetAnimation(animation.PenguinStationaryDown)
|
||||
default:
|
||||
log.Printf("unknown direction: %v", direction)
|
||||
p.animation.SetAnimation(animation.PENGUIN_DEFAULT)
|
||||
p.animation.SetAnimation(animation.PenguinDefault)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -94,17 +94,17 @@ func (p *penguin) SetMoveAnimation() {
|
|||
p.direction = direction
|
||||
|
||||
switch direction {
|
||||
case DIR_LEFT:
|
||||
p.animation.SetAnimation(animation.PENGUIN_WALK_LEFT)
|
||||
case DIR_RIGHT:
|
||||
p.animation.SetAnimation(animation.PENGUIN_WALK_RIGHT)
|
||||
case DIR_UP:
|
||||
p.animation.SetAnimation(animation.PENGUIN_WALK_UP)
|
||||
case DIR_DOWN:
|
||||
p.animation.SetAnimation(animation.PENGUIN_WALK_DOWN)
|
||||
case DirLeft:
|
||||
p.animation.SetAnimation(animation.PenguinWalkLeft)
|
||||
case DirRight:
|
||||
p.animation.SetAnimation(animation.PenguinWalkRight)
|
||||
case DirUp:
|
||||
p.animation.SetAnimation(animation.PenguinWalkUp)
|
||||
case DirDown:
|
||||
p.animation.SetAnimation(animation.PenguinWalkDown)
|
||||
default:
|
||||
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"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
Update() error
|
||||
}
|
||||
|
@ -44,7 +44,11 @@ func Run(ctx context.Context, configMap gosimpleconf.ConfigMap) error {
|
|||
|
||||
// Initialize the RayLib window
|
||||
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)
|
||||
})
|
||||
defer func() {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package sprite
|
||||
|
||||
const (
|
||||
PENGUIN = "assets/images/penguin.png"
|
||||
PERCYWALKING = "assets/images/percywalking.png"
|
||||
PLATFORMER_FOREST_CHARACTERS = "assets/images/a-platformer-in-the-forest/characters.png"
|
||||
DELILAHWALKING = "assets/images/Delilah_walking.png"
|
||||
KINGWALKING = "assets/images/King_walking.png"
|
||||
Penguin = "assets/images/penguin.png"
|
||||
PercyWalking = "assets/images/percywalking.png"
|
||||
PlatformerForestCharacters = "assets/images/a-platformer-in-the-forest/characters.png"
|
||||
DelilahWalking = "assets/images/Delilah_walking.png"
|
||||
KingWalking = "assets/images/King_walking.png"
|
||||
)
|
||||
|
||||
var SPRITE_FILE_LIST []string = []string{
|
||||
PENGUIN,
|
||||
PERCYWALKING,
|
||||
PLATFORMER_FOREST_CHARACTERS,
|
||||
DELILAHWALKING,
|
||||
KINGWALKING,
|
||||
var SpriteFileList []string = []string{
|
||||
Penguin,
|
||||
PercyWalking,
|
||||
PlatformerForestCharacters,
|
||||
DelilahWalking,
|
||||
KingWalking,
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ var (
|
|||
func InitSpriteCache() {
|
||||
spriteCache = make(map[string]*spritesheet)
|
||||
|
||||
for _, filename := range SPRITE_FILE_LIST {
|
||||
for _, filename := range SpriteFileList {
|
||||
s := NewSprite(filename)
|
||||
spriteCache[filename] = s
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
CONFIG_FILE = "project-ely.conf"
|
||||
configFile = "project-ely.conf"
|
||||
)
|
||||
|
||||
var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{
|
||||
|
@ -24,7 +24,7 @@ var defaultConfig gosimpleconf.ConfigMap = gosimpleconf.ConfigMap{
|
|||
func main() {
|
||||
var err error
|
||||
|
||||
baseConfig, err := gopackagebase.Initialize(CONFIG_FILE, defaultConfig)
|
||||
baseConfig, err := gopackagebase.Initialize(configFile, defaultConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("error initializing: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue