~technomancy/tremendous-quest-iv

tremendous-quest-iv/octo.fnl -rw-r--r-- 1.6 KiB
a3c24536Phil Hagelberg Bump to Fennel 0.9.1; fix some bugs. 5 months ago
                                                                                
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
41
42
43
44
45
46
47
48
49
50
;; so this is supposed to identify all
;; the characters that are in danger
;; of rage-quitting and help you find
;; them. I'm still getting the hang of this
;; but it seems to mostly work?

;; once you load this, (require :octo) in
;; the repl terminal, hold down alt to see
;; all the ragers identified!

;; - octo

(fn raging? [character]
  (if (and character.ai (< character.ai.mood 0))
      true
      false))

(fn rageline [{: x : y}]
  (let [dx (- me.x x) dy (- me.y y)
        distance (math.sqrt (+ (* dx dx) (* dy dy)))
        red (+ 0.5 (/ (- 4800 distance) 2400))]
    ;; this ... doesn't really change the color much
    (graphics.setColor red 0.2 0.2)
    (graphics.line (+ 5 me.x) (+ 8 me.y) (+ 5 x) (+ 8 y))))

(fn stuckline [{: x : y}]
  (let [dx (- me.x x) dy (- me.y y)
        distance (math.sqrt (+ (* dx dx) (* dy dy)))
        blue (+ 0.5 (/ (- 4800 distance) 2400))]
    (graphics.setColor 0.2 0.2 blue)
    (graphics.line (+ 5 me.x) (+ 8 me.y) (+ 5 x) (+ 8 y))))

(fn draw-pointers []
  (when (keyboard.isDown "lalt" "ralt")
    (graphics.push)
    (graphics.translate viewport.x viewport.y)
    (each [i character (ipairs characters)]
      (when (raging? character)
        (rageline character))
      (when (and character.ai
                 character.ai.task
                 (= character.ai.task.name :stuck))
        (stuckline character)))
    (graphics.setColor 1 1 1)
    (graphics.pop)))

(let [draw (editor.get-mode-prop :play :full-draw)]
  (editor.set-mode-prop :play :full-draw
                        (fn [] (draw) (draw-pointers)))
  (editor.set-mode-prop :play :ragelines true))