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 /person.go | |
| parent | 03adccc9ec7a84a08f9d62287b42e09ce2b2963e (diff) | |
feat: Move to destination
Diffstat (limited to 'person.go')
| -rw-r--r-- | person.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -10,6 +10,7 @@ type Person struct { size Point Position Point IsSelected bool + move Move image *ebiten.Image selectedImage *ebiten.Image } @@ -38,3 +39,19 @@ func (p Person) CollisionBounds() Rectangle { p.Position.Add(p.size.Div(2)), } } + +func (p *Person) MoveTo(destination Point) { + p.move = Move{IsActive: true, Destination: destination} +} + +func (p *Person) Update() { + speed := 2 + if p.move.IsActive { + remainingMove := p.move.Destination.Sub(p.Position) + delta := remainingMove.Mul(speed).Div(int(Length(remainingMove))) + p.Position = p.Position.Add(delta) + if Distance(p.Position, p.move.Destination) < float64(speed) { + p.move.IsActive = false + } + } +} |
