forked from x-hgg-x/goecsengine
/
main.go
62 lines (48 loc) · 1.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"github.com/ghtalpo/goecsengine/loader"
r "github.com/ghtalpo/goecsengine/resources"
s "github.com/ghtalpo/goecsengine/states"
"github.com/ghtalpo/goecsengine/utils"
w "github.com/ghtalpo/goecsengine/world"
"github.com/hajimehoshi/ebiten/v2"
)
const (
windowWidth = 600
windowHeight = 600
)
type mainGame struct {
world w.World
stateMachine s.StateMachine
}
func (game *mainGame) Layout(outsideWidth, outsideHeight int) (int, int) {
return windowWidth, windowHeight
}
func (game *mainGame) Update() error {
game.stateMachine.Update(game.world)
return nil
}
func (game *mainGame) Draw(screen *ebiten.Image) {
game.stateMachine.Draw(game.world, screen)
}
func main() {
world := w.InitWorld(&Components{})
// Init screen dimensions
world.Resources.ScreenDimensions = &r.ScreenDimensions{Width: windowWidth, Height: windowHeight}
// Load controls
axes := []string{RotationAxis, DepthAxis}
actions := []string{AddEntityAction, DeleteEntityAction}
controls, inputHandler := loader.LoadControls("config/controls.toml", axes, actions)
world.Resources.Controls = &controls
world.Resources.InputHandler = &inputHandler
// Load sprite sheets
spriteSheets := loader.LoadSpriteSheets("metadata/spritesheets.toml")
world.Resources.SpriteSheets = &spriteSheets
// Load fonts
fonts := loader.LoadFonts("metadata/fonts.toml")
world.Resources.Fonts = &fonts
ebiten.SetWindowResizable(true)
ebiten.SetWindowSize(windowWidth, windowHeight)
ebiten.SetWindowTitle("Demo")
utils.LogError(ebiten.RunGame(&mainGame{world, s.Init(&GameplayState{}, world)}))
}