aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2023-08-26 10:51:49 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2023-08-26 10:51:49 +0200
commitbfd7f2ed0499f8285c41cf18c3a3cb16a08a95f5 (patch)
tree9c982a7ffce5c72c46b4985f51b05bd0bcb2dde1 /main.go
parent4d03ba264a956734f067915224bff63ee398b73e (diff)
refactor: Use person image size
Diffstat (limited to 'main.go')
-rw-r--r--main.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/main.go b/main.go
index 1de0da6..f2b6c64 100644
--- a/main.go
+++ b/main.go
@@ -57,7 +57,10 @@ func (g *Game) Draw(screen *ebiten.Image) {
screen.Fill(shallowWaterColor)
soil.Fill(soilColor)
for _, p := range g.Persons {
- soil.DrawImage(p.Image(), GetDrawImageOptions(p.Size(), p.Position))
+ bounds := p.Image().Bounds()
+ op := &ebiten.DrawImageOptions{}
+ op.GeoM.Translate(p.Position.X-float64(bounds.Dx())/2, p.Position.Y-float64(bounds.Dy())/2)
+ soil.DrawImage(p.Image(), op)
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(soil.Position.X, soil.Position.Y)
@@ -72,7 +75,7 @@ func main() {
ebiten.SetWindowSize(1280, 960)
ebiten.SetWindowTitle("Age of Empire")
game := &Game{}
- mainPerson := NewPerson(Vec{X: 120, Y: 80})
+ mainPerson := NewPerson(Vec{float64(soil.Image.Bounds().Dx()) / 2, float64(soil.Image.Bounds().Dy()) / 2})
game.Persons = append(game.Persons, &mainPerson)
if err := ebiten.RunGame(game); err != nil {
panic(err)