blob: f2cee2ba49b49bd5feffda967136334542e9c681 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package main
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
}
|