-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpauseScene.go
52 lines (39 loc) · 1.17 KB
/
pauseScene.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
package foodzy
import (
"github.com/co0p/foodzy/component"
"github.com/co0p/foodzy/internal/ecs"
"github.com/co0p/foodzy/internal/scene"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
const PauseSceneName = "pause"
type PauseScene struct {
scene.GameScene
resumeAction ActionType
}
func NewPauseScene(resumeAction ActionType) *PauseScene {
txt := component.Text{Value: "PAUSE", Color: PrimaryColor, Font: &FontHuge}
posX, posY := txt.RelativeCenter(ScreenWidth, ScreenHeight)
transform := component.Transform{X: posX, Y: posY, Z: 1, Scale: 1}
pauseText := ecs.NewEntity("pause", true)
pauseText.AddComponents(&transform, &txt)
entityManager := ecs.EntityManager{}
entityManager.AddEntity(NewBackground())
entityManager.AddEntity(pauseText)
s := &PauseScene{resumeAction: resumeAction}
s.Systems = append(s.Systems,
NewSpriteRenderSystem(&entityManager),
NewTextRenderSystem(&entityManager),
)
return s
}
func (s *PauseScene) Update() error {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
s.resumeAction(nil)
return nil
}
return s.GameScene.Update()
}
func (s *PauseScene) Name() string {
return PauseSceneName
}