-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
85 lines (68 loc) · 2.72 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
_ "image/png"
gc "github.com/x-hgg-x/arkanoid-go/lib/components"
gloader "github.com/x-hgg-x/arkanoid-go/lib/loader"
gr "github.com/x-hgg-x/arkanoid-go/lib/resources"
gs "github.com/x-hgg-x/arkanoid-go/lib/states"
"github.com/x-hgg-x/goecsengine/loader"
er "github.com/x-hgg-x/goecsengine/resources"
es "github.com/x-hgg-x/goecsengine/states"
"github.com/x-hgg-x/goecsengine/utils"
w "github.com/x-hgg-x/goecsengine/world"
"github.com/hajimehoshi/ebiten/v2"
)
const (
gameWidth = 720
gameHeight = 600
)
type mainGame struct {
world w.World
stateMachine es.StateMachine
}
func (game *mainGame) Layout(outsideWidth, outsideHeight int) (int, int) {
return gameWidth, gameHeight
}
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(&gc.Components{})
// Init screen dimensions
world.Resources.ScreenDimensions = &er.ScreenDimensions{Width: gameWidth, Height: gameHeight}
// Load controls
axes := []string{gr.PaddleAxis}
actions := []string{gr.ReleaseBallAction, gr.BallAttractionAction}
controls, inputHandler := loader.LoadControls("config/controls.toml", axes, actions)
world.Resources.Controls = &controls
world.Resources.InputHandler = &inputHandler
// Load sprite sheets
spriteSheets := loader.LoadSpriteSheets("assets/metadata/spritesheets/spritesheets.toml")
world.Resources.SpriteSheets = &spriteSheets
// Load fonts
fonts := loader.LoadFonts("assets/metadata/fonts/fonts.toml")
world.Resources.Fonts = &fonts
// Load prefabs
world.Resources.Prefabs = &gr.Prefabs{
Menu: gr.MenuPrefabs{
MainMenu: gloader.PreloadEntities("assets/metadata/entities/ui/main_menu.toml", world),
PauseMenu: gloader.PreloadEntities("assets/metadata/entities/ui/pause_menu.toml", world),
GameOverMenu: gloader.PreloadEntities("assets/metadata/entities/ui/game_over_menu.toml", world),
LevelCompleteMenu: gloader.PreloadEntities("assets/metadata/entities/ui/level_complete_menu.toml", world),
},
Game: gr.GamePrefabs{
Background: gloader.PreloadEntities("assets/metadata/entities/background.toml", world),
Game: gloader.PreloadEntities("assets/metadata/entities/game.toml", world),
Score: gloader.PreloadEntities("assets/metadata/entities/ui/score.toml", world),
Life: gloader.PreloadEntities("assets/metadata/entities/ui/life.toml", world),
},
}
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
ebiten.SetWindowSize(gameWidth, gameHeight)
ebiten.SetWindowTitle("Arkanoid")
utils.LogError(ebiten.RunGame(&mainGame{world, es.Init(&gs.MainMenuState{}, world)}))
}