From 89150a146d14c593aa7aa4bfb5569f76e62a2428 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sat, 26 Aug 2023 11:49:02 +0200 Subject: refactor: Move logic into Move --- move.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'move.go') diff --git a/move.go b/move.go index 916e580..f2cee2b 100644 --- a/move.go +++ b/move.go @@ -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 +} -- cgit v1.3