diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-08-26 11:34:03 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-08-26 11:34:03 +0200 |
| commit | d4283a02e30348e73bce786e67e2b1a17955c679 (patch) | |
| tree | 27576b3a1b71ea4c73f782f891012ea75880c364 /main.go | |
| parent | 03adccc9ec7a84a08f9d62287b42e09ce2b2963e (diff) | |
feat: Move to destination
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -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}) |
