-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (58 loc) · 1.9 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
package core
import (
rl "github.com/gen2brain/raylib-go/raylib"
"github.com/jossse69/PUZZ/ecs"
"github.com/jossse69/PUZZ/renderer"
)
// Game represents the core engine structure.
type Game struct {
Renderer *renderer.Renderer
Systems *ecs.SystemManager
Entities *ecs.EntityManager
Components *ecs.ComponentManager
// Load calls once when the game starts, useful for loading resources.
Load func()
// Update is called every frame.
// It receives the current frame time in seconds. (AKA 'delta time')
Update func(dt float32)
// Draw is called every frame, but after Update and after drawing is started, so it can be used for drawing game graphics.
Draw func()
}
// NewGame initializes a new PUZZ game instance.
func NewGame(gameWidth, gameHeight int, title string) *Game {
// Initialize the Raylib window and other settings here if not already done in Renderer.
game := &Game{
Renderer: renderer.NewRenderer(gameWidth, gameHeight, title),
Systems: ecs.NewSystemManager(),
Entities: ecs.NewEntityManager(),
Components: ecs.NewComponentManager(),
}
return game
}
// Run starts the main game loop.
func (game *Game) Run() {
if game.Load != nil {
game.Load()
}
for !rl.WindowShouldClose() {
dt := rl.GetFrameTime()
// Check if the Update function is defined before calling it
if game.Update == nil {
panic("Update function is not defined! Please define it before running the game.")
}
game.Update(dt)
game.Renderer.StartDrawing()
// Check if the Draw function is defined before attempting to call it
if game.Draw == nil {
panic("Draw function is not defined! Please define it before running the game.")
}
game.Draw()
game.Renderer.DrawOnScreen()
}
game.Close()
}
// Close cleans up resources and closes the game window.
func (game *Game) Close() {
game.Renderer.Close()
}
// Additional methods to manage game state, handle input, etc., can be added here.