From 5af6361f22d727a4abacd724cf9152e67f73328a Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 9 Jul 2025 07:39:39 +0200 Subject: Export draw logic --- draw.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'draw.go') diff --git a/draw.go b/draw.go index 90c1134..ba4f651 100644 --- a/draw.go +++ b/draw.go @@ -1,11 +1,13 @@ package main import ( + "age_of_empires/physics" "fmt" "image/color" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/text/v2" + "github.com/hajimehoshi/ebiten/v2/vector" ) func (e *Entity) Draw(g *Game, screen *ebiten.Image) { @@ -39,5 +41,37 @@ func (e *Entity) Draw(g *Game, screen *ebiten.Image) { Size: 40, }, op) } + if e.Move.Value.IsActive { + last := e.Position.Value + dx := +e.Image.Value.Bounds().Dx() / 2 + dy := +e.Image.Value.Bounds().Dy() / 2 + for _, point := range e.Move.Value.Path { + vector.StrokeLine(screen, float32(last.X+dx), float32(last.Y+dy), float32(point.X+dx), float32(point.Y+dy), 10.0, color.RGBA{256 * 3 / 16, 256 * 3 / 16, 256 * 3 / 16, 256 / 4}, true) + last = point + } + } + } +} + +func (g *Game) Draw(screen *ebiten.Image) { + x, y := ebiten.CursorPosition() + cursor := physics.Point{X: x, Y: y} + screen.Fill(soilColor) + for _, e := range g.Entities { + e.Draw(g, screen) + } + if g.Selection.IsActive { + vector.StrokeRect(screen, float32(g.Selection.Start.X), float32(g.Selection.Start.Y), float32(cursor.X-g.Selection.Start.X), float32(cursor.Y-g.Selection.Start.Y), 10.0, color.RGBA{256 * 3 / 16, 256 * 3 / 16, 256 * 3 / 16, 256 / 4}, true) } + bannerHeight := float32(200) + vector.DrawFilledRect(screen, 0, 0, float32(3200), bannerHeight, color.White, true) + + resourceText := fmt.Sprintf("Resources: %d", g.ResourceAmount) + op := &text.DrawOptions{} + op.GeoM.Translate(25, 25) + op.ColorScale.ScaleWithColor(color.Black) + text.Draw(screen, resourceText, &text.GoTextFace{ + Source: g.FaceSource, + Size: 100, + }, op) } -- cgit v1.3