diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-08-26 11:49:02 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-08-26 11:49:02 +0200 |
| commit | 89150a146d14c593aa7aa4bfb5569f76e62a2428 (patch) | |
| tree | 336dc263594154b871dd625eed0d8402c25b1e83 /move.go | |
| parent | 1f0d742572bd246d715503b774ff6b92c554aa4a (diff) | |
refactor: Move logic into Move
Diffstat (limited to 'move.go')
| -rw-r--r-- | move.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -4,3 +4,16 @@ type Move struct { IsActive bool Destination Point } + +func (m *Move) Update(position Point, speed int) Point { + if !m.IsActive { + return position + } + remainingMove := m.Destination.Sub(position) + delta := remainingMove.Mul(speed).Div(int(Length(remainingMove))) + next := position.Add(delta) + if Distance(next, m.Destination) < float64(speed) { + m.IsActive = false + } + return next +} |
