diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-01-31 15:39:55 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:45 +0100 |
| commit | 01b8c63effcdf862f6de2ec86ab47b5adf2a49bf (patch) | |
| tree | 14fbf3fd6b719f4140e2e7d96614a1a21a4eba46 /go | |
| parent | e4895887ebd21cbc1dc198da28bf7a930df89b82 (diff) | |
| download | muhqs-game-01b8c63effcdf862f6de2ec86ab47b5adf2a49bf.tar.gz muhqs-game-01b8c63effcdf862f6de2ec86ab47b5adf2a49bf.zip | |
make screen dimensions members of the game object
Diffstat (limited to 'go')
| -rw-r--r-- | go/client/main.go | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/go/client/main.go b/go/client/main.go index 62fa52c1..10279085 100644 --- a/go/client/main.go +++ b/go/client/main.go @@ -15,8 +15,8 @@ import ( ) const ( - screenWidth = 800 - screenHeight = 1024 + SCREEN_WIDTH = 800 + SCREEN_HEIGHT = 1024 DEFAULT_BUTTON_HEIGHT = 40 PASS_BUTTON_WIDTH = 100 @@ -72,6 +72,8 @@ func (h *hoverDetector) startedHovering() bool { } type Game struct { + screenWidth, screenHeight int + selectedObject interface{} hoverDetector hoverDetector @@ -98,12 +100,16 @@ type Game struct { } func NewGame() *Game { - g := &Game{} + g := &Game{ + screenWidth: SCREEN_WIDTH, + screenHeight: SCREEN_HEIGHT, + } + g.widgets = []ui.Widget{} g.gameState = game.NewState() - g.passButton = ui.NewSimpleButton(screenWidth-PASS_BUTTON_WIDTH, - screenHeight-DEFAULT_BUTTON_HEIGHT, + g.passButton = ui.NewSimpleButton(g.screenWidth-PASS_BUTTON_WIDTH, + g.screenHeight-DEFAULT_BUTTON_HEIGHT, PASS_BUTTON_WIDTH, DEFAULT_BUTTON_HEIGHT, "Pass", @@ -120,7 +126,7 @@ func NewGame() *Game { } }) - g.stackBuffer = ui.NewBuffer(screenWidth-STACK_BUFFER_WIDTH, g.passButton.Y-400, + g.stackBuffer = ui.NewBuffer(g.screenWidth-STACK_BUFFER_WIDTH, g.passButton.Y-400, STACK_BUFFER_WIDTH, 400) return g } @@ -178,13 +184,13 @@ func (g *Game) initPlayerUi(player *game.Player) { g.handLayer = ui.NewHandView(0, g.mapView.Height(), HAND_VIEW_WIDTH, - screenHeight-g.mapView.Height()-DEFAULT_BUTTON_HEIGHT, + g.screenHeight-g.mapView.Height()-DEFAULT_BUTTON_HEIGHT, player.Hand, true) g.addWidget(g.handLayer) g.stateBar = ui.NewStateBar(0, - screenHeight-DEFAULT_BUTTON_HEIGHT, + g.screenHeight-DEFAULT_BUTTON_HEIGHT, STATE_BAR_WIDTH, DEFAULT_BUTTON_HEIGHT, g.gameState, @@ -192,7 +198,7 @@ func (g *Game) initPlayerUi(player *game.Player) { g.addWidget(g.stateBar) g.discardPileButton = ui.NewSimpleButton(g.stateBar.Width, - screenHeight-DEFAULT_BUTTON_HEIGHT, + g.screenHeight-DEFAULT_BUTTON_HEIGHT, 150, DEFAULT_BUTTON_HEIGHT, "DiscardPile", @@ -207,12 +213,12 @@ func (g *Game) initPlayerUi(player *game.Player) { g.addWidget(g.discardPileButton) x = g.discardPileButton.X + g.discardPileButton.Width/2 - y = screenHeight - DEFAULT_BUTTON_HEIGHT + y = g.screenHeight - DEFAULT_BUTTON_HEIGHT g.discardPileView = ui.NewPocList(x, y, g.activePlayer.DiscardPile) if !g.storesOnMap { x = g.stateBar.Width + g.discardPileButton.Width - y = screenHeight - DEFAULT_BUTTON_HEIGHT + y = g.screenHeight - DEFAULT_BUTTON_HEIGHT g.storeButton = ui.NewSimpleButton(x, y, 150, DEFAULT_BUTTON_HEIGHT, @@ -227,7 +233,7 @@ func (g *Game) initPlayerUi(player *game.Player) { g.addWidget(g.storeView) x = g.storeButton.X + g.storeButton.Width/2 - y = screenHeight - DEFAULT_BUTTON_HEIGHT + y = g.screenHeight - DEFAULT_BUTTON_HEIGHT g.storeView = ui.NewPocList(x, y, g.activePlayer.Store) } } @@ -351,7 +357,7 @@ func (g *Game) handlePlayerNotifications() { ctx := n.Context.([]int) min, max := ctx[0], ctx[1] promptTxt := fmt.Sprintf("Select between %d and %d hand cards", min, max) - g.prompt = ui.NewHandCardPrompt(screenHeight/2, screenWidth, promptTxt) + g.prompt = ui.NewHandCardPrompt(g.screenHeight/2, g.screenWidth, promptTxt) g.addWidget(g.prompt) g.showPassButton() } @@ -459,7 +465,7 @@ func (g *Game) handleHover(obj interface{}, x, y int) { switch obj := obj.(type) { case *game.Card: wx, wy := x, y - if x+500 > screenWidth || y+700 > screenHeight { + if x+500 > g.screenWidth || y+700 > g.screenHeight { wx = x - 500 wy = y - 700 } @@ -540,17 +546,16 @@ func (g *Game) Draw(screen *ebiten.Image) { } func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { - return screenWidth, screenHeight + return g.screenWidth, g.screenHeight } func main() { font.InitFont() + g := NewGameFromMap("the-kraken") - ebiten.SetWindowSize(screenWidth, screenHeight) + ebiten.SetWindowSize(g.screenWidth, g.screenHeight) ebiten.SetWindowTitle("Muhq's Game") - g := NewGameFromMap("the-kraken") - nautics := `1 nautics/barge 1 nautics/captain 1 nautics/fisher |
