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
|
package main
import (
"log"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
// "muhq.space/muhqs-game/go/game"
"muhq.space/muhqs-game/go/ui"
)
const (
START_BUTTON_WIDTH = 150
START_BUTTON_HEIGHT = 50
)
type StartMenu struct {
app *app
width, height int
playerName string
startDeck string
remote string
mapPath string
widgets []ui.Widget
}
func NewStartMenu(app *app) *StartMenu {
m := &StartMenu{app: app}
return m
}
func (m *StartMenu) build() {
m.widgets = append(m.widgets, ui.NewSimpleButton(
(m.width-START_BUTTON_WIDTH)/2,
(m.height-START_BUTTON_HEIGHT)/2,
150,
50,
"Start",
func(*ui.SimpleButton) {
m.app.active = m.next()
}))
}
func (m *StartMenu) Update() error {
if m.widgets == nil {
m.build()
}
x, y := ebiten.CursorPosition()
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
for _, w := range m.widgets {
if !w.Contains(x, y) {
continue
}
if btn, ok := w.(ui.Button); ok {
btn.Click(x, y)
}
}
}
return nil
}
func (m *StartMenu) Draw(screen *ebiten.Image) {
for _, w := range m.widgets {
w.Draw(screen)
}
}
func (m *StartMenu) Layout(width, height int) (int, int) {
return m.width, m.height
}
func (m *StartMenu) next() ebiten.Game {
if m.remote != "" {
log.Fatal("Remote games are currently not implemented")
}
g := newGame(m.app).loadMap(m.mapPath).addActivePlayer(m.playerName, m.startDeck)
if m.mapPath == "the-kraken" {
idx := len(g.gameState.Players)
color := playerColors[idx]
g.gameState.AddKraken()
g.gameState.Players[idx].Color = color
}
return g.Start()
}
|