aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/main.go b/main.go
index 49e9d02..60a3b76 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,6 @@
package main
import (
- "fmt"
"image/color"
"github.com/hajimehoshi/ebiten/v2"
@@ -28,33 +27,38 @@ type Game struct {
}
func (g *Game) Update() error {
+ if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonRight) {
+ x, y := ebiten.CursorPosition()
+ tileClick := Point{x - soil.Position.X, y - soil.Position.Y}
+ for _, p := range g.Persons {
+ if p.IsSelected {
+ p.MoveTo(tileClick)
+ }
+ }
+ }
if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) {
x, y := ebiten.CursorPosition()
tileClick := Point{x - soil.Position.X, y - soil.Position.Y}
- fmt.Println("Click: ", tileClick)
for _, p := range g.Persons {
p.IsSelected = false
- fmt.Println("Person: ", p.Position)
if tileClick.In(p.CollisionBounds()) {
- fmt.Println("Person selected")
p.IsSelected = true
}
}
}
+ for _, p := range g.Persons {
+ p.Update()
+ }
return nil
}
-var shallowWaterColor = color.RGBA{0x80, 0xa0, 0xc0, 0xff}
-
func (g *Game) Draw(screen *ebiten.Image) {
- screen.Fill(shallowWaterColor)
+ screen.Fill(color.RGBA{0x80, 0xa0, 0xc0, 0xff})
soil.Fill(soilColor)
for _, p := range g.Persons {
bounds := p.Image().Bounds()
- fmt.Println("Person bounds: ", bounds)
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(p.Position.X-bounds.Dx()/2), float64(p.Position.Y-bounds.Dy()/2))
- fmt.Println("Person position:", p.Position, "Draw geom: ", op.GeoM)
soil.DrawImage(p.Image(), op)
}
op := &ebiten.DrawImageOptions{}
@@ -67,7 +71,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeigh
}
func main() {
- ebiten.SetWindowSize(1280, 960)
+ ebiten.SetWindowSize(640, 480)
ebiten.SetWindowTitle("Age of Empire")
game := &Game{}
mainPerson := NewPerson(Point{soil.Image.Bounds().Dx() / 2, soil.Image.Bounds().Dy() / 2})