diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-01-31 22:19:28 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:45 +0100 |
| commit | 3fd15c9b83fff074b588ff9688f9e49aab38cd32 (patch) | |
| tree | faf0710b755118dcd5ce7ae99fade3300e369292 /go/client/startMenu.go | |
| parent | 01b8c63effcdf862f6de2ec86ab47b5adf2a49bf (diff) | |
| download | muhqs-game-3fd15c9b83fff074b588ff9688f9e49aab38cd32.tar.gz muhqs-game-3fd15c9b83fff074b588ff9688f9e49aab38cd32.zip | |
intermediate commit
Diffstat (limited to 'go/client/startMenu.go')
| -rw-r--r-- | go/client/startMenu.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/go/client/startMenu.go b/go/client/startMenu.go new file mode 100644 index 00000000..07c4f92b --- /dev/null +++ b/go/client/startMenu.go @@ -0,0 +1,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() +} |
