Files
football/internal/render/renderer.go
2026-05-12 11:21:10 +03:00

68 lines
1.5 KiB
Go

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{}
func NewRenderer() *Renderer {
return &Renderer{}
}
func (r *Renderer) DrawWorld(screen *ebiten.Image, world *game.World) {
// Draw Puck
vector.DrawFilledCircle(
screen,
float32(world.Puck.Position.X),
float32(world.Puck.Position.Y),
float32(world.Puck.Radius),
color.White,
true,
)
// Draw Players
for _, p := range world.Players {
var c color.Color
if p.Team == entities.TeamRed {
c = color.RGBA{R: 255, G: 0, B: 0, A: 255}
} else {
c = color.RGBA{R: 0, G: 0, B: 255, A: 255}
}
vector.DrawFilledCircle(
screen,
float32(p.Position.X),
float32(p.Position.Y),
float32(p.Radius),
c,
true,
)
}
}
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)
}