~technomancy/tremendous-quest-iv

tremendous-quest-iv/characters.fnl -rw-r--r-- 2.8 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
51
52
53
54
55
56
57
58
59
60
61
62
(local lume (require "polywell.lib.lume"))
(local item (require "item"))
(local dialog (require "dialog"))

;; these people have asked get their name included (regardless of gender)
;; https://hi.technomancy.us/notice/9tybSCoLrpN7VaSEro

(local nicks (lume.shuffle ["charlag" "RedGlow" "ckeen" "W10x12_UNO" "kaeedo"
                            "Follpvosten" "pxi" "greyor" "esopriester" "FiXato"
                            "m455" "enot" "a" "jookia" "cylb" "robjloranger"
                            "dch" "fra" "cpsdqs" "cage" "fudgel"
                            "emptyfortress" "Hararan"]))

(local sprites (love.graphics.newImage "assets/mobset.png"))

(local sword (love.graphics.newQuad 0 64 15 15 (sprites:getDimensions)))
(fn sword-y [y t] (math.floor (- y 8 (math.abs (- (math.fmod (* t 10) 10) 4)))))

(fn bug-item [c item]
  (fn c.convo [c]
    (dialog.say c "dunno what's going on here but my"
                item
                "is all messed up and I can't remove"
                "or de-equip it! what a drag. can you"
                "do something about it?"))
  (set c.bugged-item item))

(λ make [?name x y sprite-number]
  (let [sx (math.fmod sprite-number 20)
        sy (math.floor (/ sprite-number 20))
        quad (love.graphics.newQuad (+ (* 16 sx) 1) (* 16 sy)
                                    14 16 (sprites:getDimensions))
        item-count (-> (love.math.randomNormal 3 6)
                       (math.min 10)
                       (math.max 3))
        inventory []
        _ (for [_ 1 item-count] (table.insert inventory (item.make)))
        c {: x : y :w 12 :h 15 :speed 64
           : inventory
           :ui-color [1 1 1]
           :level (math.floor (math.max (love.math.randomNormal 10 20) 1))
           :gold (math.floor (math.max (love.math.randomNormal 3000 5000) 100))
           :quests (math.floor (math.max (love.math.randomNormal 30 50) 1))
           :diamond? (< (math.random) 0.2)
           :name (or ?name (table.remove nicks) "untitled")}]
    (when (< (love.math.random) 0.1)
      (bug-item c (lume.randomchoice inventory)))
    (fn c.draw [x y with-action?]
      (let [x (math.floor x) y (math.floor y)]
        (love.graphics.draw sprites quad (- x 1) (- y 2))
        (when with-action?
          (when c.new-convo?
            (love.graphics.print "?" (- x 8) (sword-y y c.ai.lifetime)))
          (match (-?> c (. :ai) (. :task) (. :name))
            :level-up (love.graphics.print "+" x (+ y -20 (* c.ai.task.timer 5)))
            :stuck (love.graphics.print "!!!" (- x 8) (sword-y y c.ai.task.timer))
            :rage (love.graphics.print "&%@*!" (- x 8) (sword-y y c.ai.task.timer))
            :combat (love.graphics.draw sprites sword
                                        (+ x 8) (sword-y y c.ai.task.timer))))))
    c))

{: make :count (# nicks)}