aboutsummaryrefslogtreecommitdiff
path: root/src/tail.odin
blob: 2184444ecfaac6fc422b991470d0cbd9be675f52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package demonchime

import "core:math"
import "core:math/linalg"

Tail :: struct($N: int) {
  points: [N]Vec2,
  point_max_dist: f32,
  point_rad: f32,
  color_start: Color,
  color_end: Color,
}

set_tail_position :: proc(tail: ^Tail($N), pos: Vec2, dt: f32) {
  tail.points[0] = pos
  for i in 1..<len(tail.points) {
    prev := tail.points[i - 1]
    cur := &tail.points[i]

    cur.y += 50 * dt

    dist := linalg.length2(prev - cur^)
    if dist > tail.point_max_dist*tail.point_max_dist {
      dir := linalg.normalize0(cur^ - prev)
      cur^ = prev + dir * (tail.point_max_dist - 1)
    }
  }
}

draw_tail :: proc(tail: Tail($N)) {
  for point, i in tail.points {
    renderer.tint = linalg.lerp(
      tail.color_start,
      tail.color_end,
      f32(i)/len(tail.points),
    )
    draw_circle(point, tail.point_rad)
  }
  renderer.tint = {1, 1, 1, 1}
}