forked from x-hgg-x/goecsengine
/
states.go
53 lines (40 loc) · 1.13 KB
/
states.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
package main
import (
"math/rand"
"time"
"github.com/ghtalpo/goecsengine/states"
w "github.com/ghtalpo/goecsengine/world"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
// GameplayState is the main game state
type GameplayState struct{}
// OnPause method
func (st *GameplayState) OnPause(world w.World) {}
// OnResume method
func (st *GameplayState) OnResume(world w.World) {}
// OnStart method
func (st *GameplayState) OnStart(world w.World) {
// Init rand seed
rand.Seed(time.Now().UnixNano())
// Load game and text entities
LoadEntities("metadata/start.toml", world)
LoadEntities("metadata/text.toml", world)
world.Resources.Game = NewGame()
}
// OnStop method
func (st *GameplayState) OnStop(world w.World) {
world.Resources.Game = nil
world.Manager.DeleteAllEntities()
}
// Update method
func (st *GameplayState) Update(world w.World) states.Transition {
DemoSystem(world)
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
return states.Transition{Type: states.TransQuit}
}
return states.Transition{}
}
// Draw method
func (st *GameplayState) Draw(world w.World, screen *ebiten.Image) {
}