-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_state.go
91 lines (74 loc) · 2.59 KB
/
menu_state.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
86
87
88
89
90
91
package game_manager
import (
"fmt"
)
type MenuState struct {
menuID string
gameObjects []GameObject
}
//*****************************************************************************
// NewMenuState
//*****************************************************************************
func NewMenuState() *MenuState {
return &MenuState{menuID: "MENU"}
}
//*****************************************************************************
// getStateID
//*****************************************************************************
func (ms *MenuState) getStateID() string {
return ms.menuID
}
//*****************************************************************************
// update
//*****************************************************************************
func (ms *MenuState) update(game *Game) {
for _, gameObject := range ms.gameObjects {
gameObject.update(game)
}
}
//*****************************************************************************
// render
//*****************************************************************************
func (ms *MenuState) render(game *Game) {
for _, gameObject := range ms.gameObjects {
gameObject.draw(game)
}
}
//*****************************************************************************
// resume
//*****************************************************************************
func (ms *MenuState) resume(game *Game) {
}
//*****************************************************************************
// onEnter
//*****************************************************************************
func (ms *MenuState) onEnter(game *Game) bool {
if !game.textureManager.load("assets/button.png", "playbutton", game.renderer) {
return false
}
if !game.textureManager.load("assets/exit.png", "exitbutton", game.renderer) {
return false
}
menuToPlay := func() {
game.gameStateMachine.changeState(NewPlayState())
}
exitFromMenu := func() {
game.SetRunning(false)
}
ms.gameObjects = append(ms.gameObjects, NewMenuButton(100, 100, 400, 100, "playbutton", menuToPlay))
ms.gameObjects = append(ms.gameObjects, NewMenuButton(100, 300, 400, 100, "exitbutton", exitFromMenu))
return true
}
//*****************************************************************************
// onExit
//*****************************************************************************
func (ms *MenuState) onExit(game *Game) bool {
for _, gameObject := range ms.gameObjects {
gameObject.clean()
}
ms.gameObjects = ms.gameObjects[:0]
game.textureManager.clearFromTextureMap("playbutton")
game.textureManager.clearFromTextureMap("exitbutton")
fmt.Println("exiting MenuState")
return true
}