aboutsummaryrefslogtreecommitdiff
path: root/go/client/startMenu.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-31 22:19:28 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2023-01-31 22:19:28 +0100
commitdd341b1472d65fb658f53d4d8aa1ca855df0b3bf (patch)
tree9d9fb3a704b8992b26ac2f41d4cb8663b1617956 /go/client/startMenu.go
parent1b1a6d4bc8e4a16de40f7a6cebaaacb8939d0691 (diff)
downloadmuhqs-game-dd341b1472d65fb658f53d4d8aa1ca855df0b3bf.tar.gz
muhqs-game-dd341b1472d65fb658f53d4d8aa1ca855df0b3bf.zip
intermediate commit
Diffstat (limited to 'go/client/startMenu.go')
-rw-r--r--go/client/startMenu.go92
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()
+}