-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
37 lines (27 loc) · 867 Bytes
/
game.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
package main
import (
"image/color"
"engo.io/ecs"
"engo.io/engo"
"engo.io/engo/common"
)
const buttonOpenMenu = "OpenMenu"
type game struct{}
func (g *game) Type() string { return sceneGame }
func (g *game) Preload() {}
func (g *game) Setup(world *ecs.World) {
engo.Input.RegisterButton(buttonOpenMenu, engo.Escape)
common.SetBackground(color.White)
world.AddSystem(&common.RenderSystem{})
world.AddSystem(&inputSystem{})
}
type inputSystem struct{}
// Update is ran every frame, with `dt` being the time
// in seconds since the last frame
func (is *inputSystem) Update(float32) {
if engo.Input.Button(buttonOpenMenu).JustPressed() {
engo.SetSceneByName(sceneMainMenu, true)
}
}
// Remove is called whenever an Entity is removed from the World, in order to remove it from this sytem as well
func (is *inputSystem) Remove(ecs.BasicEntity) {}