aboutsummaryrefslogtreecommitdiff
path: root/draw.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-09 07:39:39 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-09 07:39:39 +0200
commit5af6361f22d727a4abacd724cf9152e67f73328a (patch)
tree8c15f010c79ff5cf4fcbab60e8efb2cc86f02b1b /draw.go
parent1a4f1f3bd5814af2deaac4b8ccd4be33264793a8 (diff)
Export draw logic
Diffstat (limited to 'draw.go')
-rw-r--r--draw.go34
1 files changed, 34 insertions, 0 deletions
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)
}