feat(render): add UI for score and game state

This commit is contained in:
Vladimir V Maksimov
2026-05-12 11:21:10 +03:00
parent 6ed363e6de
commit 531bde3928
2 changed files with 21 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ func (g *Game) Update() error {
func (g *Game) Draw(screen *ebiten.Image) {
g.renderer.DrawWorld(screen, g.matchManager.World)
g.renderer.DrawUI(screen, g.matchManager)
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {

View File

@@ -1,12 +1,15 @@
package render
import (
"fmt"
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
"github.com/hajimehoshi/ebiten/v2/vector"
"github.com/soer/football/internal/entities"
"github.com/soer/football/internal/game"
"golang.org/x/image/font/basicfont"
)
type Renderer struct{}
@@ -45,3 +48,20 @@ func (r *Renderer) DrawWorld(screen *ebiten.Image, world *game.World) {
)
}
}
func (r *Renderer) DrawUI(screen *ebiten.Image, matchManager *game.MatchManager) {
scoreStr := fmt.Sprintf("Red: %d - Blue: %d", matchManager.ScoreRed, matchManager.ScoreBlue)
var stateStr string
switch matchManager.State {
case game.Playing:
stateStr = "State: Playing"
case game.GoalPause:
stateStr = "State: Goal Pause"
case game.MatchEnded:
stateStr = "State: Match Ended"
}
text.Draw(screen, scoreStr, basicfont.Face7x13, 10, 20, color.White)
text.Draw(screen, stateStr, basicfont.Face7x13, 10, 40, color.White)
}