-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmenu.go
121 lines (101 loc) · 2.59 KB
/
menu.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"os"
)
type Menu struct {
hidden bool
gh *Game
logo []*Sprite
start []*Sprite
scoreBoard []*Sprite
about []*Sprite
quit []*Sprite
how []*Sprite
bg *Sprite
}
func (m *Menu) Init(g *Game) {
m.gh = g
offsetX := float32(0.02)
m.logo = m.gh.tex.AddText("bintris", 0.14, 0.75, 0.6, 0.1, 0.19, EffectMetaballs, SpriteMenu)
m.start = m.gh.tex.AddText("start", 0.34+offsetX, 0.65, 0.6, 0.05, 0.05, EffectNone, SpriteMenu)
m.how = m.gh.tex.AddText("Rules", 0.34+offsetX, 0.58, 0.6, 0.05, 0.05, EffectNone, SpriteMenu)
m.scoreBoard = m.gh.tex.AddText("Score", 0.34+offsetX, 0.51, 0.6, 0.05, 0.05, EffectNone, SpriteMenu)
m.about = m.gh.tex.AddText("about", 0.34+offsetX, 0.44, 0.6, 0.05, 0.05, EffectNone, SpriteMenu)
m.quit = m.gh.tex.AddText("quit", 0.365+offsetX, 0.27, 0.6, 0.05, 0.05, EffectNone, SpriteMenu)
for i := range m.logo {
m.logo[i].ChangeEffect(EffectMetaballs)
}
m.hidden = false
}
func (m *Menu) Show() {
if !m.hidden {
return
}
m.gh.backBg.ChangeEffect(EffectMenu)
m.gh.bg.Hide()
m.hidden = false
for i := range m.logo {
m.logo[i].Show()
}
for i := range m.how {
m.how[i].Show()
}
for i := range m.start {
m.start[i].Show()
}
for i := range m.scoreBoard {
m.scoreBoard[i].Show()
}
for i := range m.about {
m.about[i].Show()
}
for i := range m.quit {
m.quit[i].Show()
}
}
func (m *Menu) Hide() {
if m.hidden {
return
}
m.hidden = true
for i := range m.logo {
m.logo[i].Hide()
}
for i := range m.how {
m.how[i].Hide()
}
for i := range m.start {
m.start[i].Hide()
}
for i := range m.scoreBoard {
m.scoreBoard[i].Hide()
}
for i := range m.about {
m.about[i].Hide()
}
for i := range m.quit {
m.quit[i].Hide()
}
}
func (m *Menu) KeyDown(x, y float32) {
if x > 0.36 && x < 0.36+(float32(len(m.start))*0.055) && y > 0.65 && y < 0.65+0.05 {
m.gh.mode.Start(GameModeNormal)
} else if x > 0.36 && x < 0.36+(float32(len(m.how))*0.055) && y > 0.58 && y < 0.58+0.05 {
m.gh.menu.Hide()
m.gh.howto.Show()
m.gh.backBg.ChangeEffect(EffectMenuStill)
} else if x > 0.36 && x < 0.36+(float32(len(m.scoreBoard))*0.055) && y > 0.51 && y < 0.51+0.05 {
m.gh.scoreboard.Show([]Score{})
m.gh.backBg.ChangeEffect(EffectMenuStill)
m.gh.menu.Hide()
} else if x > 0.36 && x < 0.36+(float32(len(m.about))*0.055) && y > 0.44 && y < 0.44+0.05 {
m.gh.menu.Hide()
m.gh.backBg.ChangeEffect(EffectMenuStill)
m.gh.about.Show()
} else if x > 0.39 && x < 0.39+(float32(len(m.quit))*0.055) && y > 0.27 && y < 0.27+0.05 {
os.Exit(0)
}
}
func (m *Menu) Hidden() bool {
return m.hidden
}