main.fnl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. (fn <-town [v] (vadd v (point -30 0)))
  2. (fn town-wall [t]
  3. (or (= t 101) (= t 102) (= t 105) (= t 154)
  4. (= t 97) (= t 144) (= t 160) (= t 153)))
  5. (fn create-town [] ;30,1 59,16
  6. (global world (make-map 29 16 1))
  7. (global tiles (make-map 29 16 0))
  8. (for [y 1 16]
  9. (for [x 30 59]
  10. (let [t (mget x y)]
  11. (gset tiles (<-town (point x y)) t)
  12. (when (town-wall t)
  13. (gset world (<-town (point x y)) 0)))))
  14. (global entities [player])
  15. (global items [])
  16. (global triggers [])
  17. (tset player :pos (<-town (point 37 10)))
  18. (populate-dist
  19. world entities
  20. (initialize-monster monster-map.townie) 3 player.pos 8)
  21. (add triggers {:stairs true :dir 1 :pos (<-town (point 53 7))})
  22. (add triggers {:store :general :pos (<-town (point 36 6))})
  23. (add triggers {:store :armory :pos (<-town (point 33 12))})
  24. (add triggers {:store :magic :pos (<-town (point 43 12))}))
  25. (fn create-level [dir]
  26. (set DEEPEST (math.max DEEPEST depth))
  27. ;create a new dungeon world
  28. ;eventually should take depth params
  29. (global world (make-map 64 64 0))
  30. (global tiles (make-map 64 64 0))
  31. (drunk-dungeon world (point 16 16) 100 1)
  32. (for [i 1 3]
  33. (drunk-dungeon world (random-tile world 1) 100 1 30))
  34. (for [i 1 (roll [1 4])] ;water
  35. (drunk-dungeon world (random-tile world 1) 20 2 20))
  36. (map->tiles world tiles (rand-nth
  37. [themes.stone themes.bright themes.stone themes.bright themes.woods]))
  38. (global entities [player])
  39. (global items [])
  40. (global triggers [])
  41. (tset player :pos (random-tile world 1))
  42. (if (= dir 1) ;down
  43. (place-clone-at up-stair triggers player.pos)
  44. (= dir -1) ;up
  45. (place-clone-at down-stair triggers player.pos))
  46. (let [mobs (filter (fn [o] (and (> o.level 0) (<= o.level depth)) )
  47. (vals monster-map))
  48. cnt (+ 2 depth (roll [1 4]))]
  49. (for [i 1 cnt]
  50. (populate-dist world entities
  51. (initialize-monster (rand-nth mobs)) 1 player.pos 8)))
  52. (if (= depth 10)
  53. (do
  54. (populate-dist world entities
  55. (initialize-monster (. monster-map :ohno)) 1 player.pos 8)
  56. (place-doors 0 1 player.pos 40))
  57. (place-doors 2 2 player.pos 40))
  58. (let [itms (filter (fn [o] (or (<= o.level (inc depth)) (chance 5)))
  59. (vals item-map))
  60. cnt (+ 1 depth (roll [1 4]))]
  61. (for [i 1 10]
  62. (let [o (initialize-item (rand-nth itms))]
  63. (populate world items o 1)))))
  64. (fn hud [v]
  65. (print (.. "FLOOR " depth) 8 1 6)
  66. (print (.. "LVL " player.level) 62 1 13)
  67. (print (.. "$ " (math.floor player.gold)) 100 1 14)
  68. (print (.. "EXP " (math.floor player.exp) "/" (exp-next player.level)) 160 1 7)
  69. (print (.. "hp " player.hp "/" player.maxhp) 8 129 9)
  70. (var action-name "") ;TODO clean this up
  71. (let [t (trigger-at player.pos)
  72. i (items-at player.pos)]
  73. (if
  74. (not (empty? i))
  75. (set action-name (.. "get " (. (first i) :name)))
  76. (and t t.stairs (= t.dir 1))
  77. (set action-name "descend")
  78. (and t t.stairs (= t.dir -1))
  79. (set action-name "ascend")
  80. (set action-name "wait")))
  81. (print (or (first msgs) (.. "[z] commands, [x] " action-name)) 70 129)
  82. (print (.. "equipment" ) v.x (+ v.y 0) 9)
  83. (spr 208 v.x (+ v.y 8) 0)
  84. (spr 209 v.x (+ v.y 16) 0)
  85. (spr 210 v.x (+ v.y 24) 0)
  86. (when player.equip.head
  87. (item-print player.equip.head (point (+ v.x 10) (+ v.y 8))))
  88. (when player.equip.body
  89. (item-print player.equip.body (point (+ v.x 10) (+ v.y 16))))
  90. (when player.equip.feet
  91. (item-print player.equip.feet (point (+ v.x 10) (+ v.y 24))))
  92. (print (.. "weapon" ) v.x (+ v.y 32) 9)
  93. (if player.weapon
  94. (item-print player.weapon (point v.x (+ v.y 40))))
  95. (print (.. "inventory " ) v.x (+ v.y 48) 9)
  96. (each [i o (ipairs player.inventory)]
  97. (item-print o (point (+ v.x 4) (+ v.y 48 (* i 8))))))
  98. (fn draw []
  99. (cls 1)
  100. (clip 8 8 120 120)
  101. (cls 0)
  102. (draw-map tiles (->view (point 0 0)) identity)
  103. (sprites triggers)
  104. (sprites items)
  105. (sprites entities)
  106. (draw-fx)
  107. (clip)
  108. ;(print DEBUG)
  109. (hud (point 132 8))
  110. (if (dialogue?) ((last _dialogue))))
  111. (fn center-print [s x y c]
  112. ;pretend fixed with font
  113. (print s (- x (* (# s) 4.5 0.5)) y (or c 15)))
  114. (fn init []
  115. (set change-level create-level)
  116. (if quickstart?
  117. (change-level)
  118. (create-town))
  119. (song! 0)
  120. (draw))
  121. (fn draw-death [] ;216 232
  122. (let [v creditsv
  123. v2 (vadd v (point 0 100))]
  124. (cls 0)
  125. (center-print (if DEATHMSG "You have prevailed!" "You have perished..") v.x v.y)
  126. (spr (if DEATHMSG 218 216) v.x (- v.y 32) 0 1 0 0 2 2)
  127. (center-print GAMENAME v.x v2.y 6)
  128. (center-print "2019" (+ v.x 5) (+ v2.y 8) 11)
  129. (center-print "by" (+ v.x 5) (+ v2.y 40) 8)
  130. (center-print "selfsame & equa" (+ v.x -2) (+ v2.y 48) 9)
  131. (center-print "made for Lisp Game Jam" v.x (+ v2.y 100) 12)
  132. (center-print "(press x to restart)" v.x (+ v2.y 150) 4)
  133. (when (btnp 5)
  134. (set LOOP :game)
  135. (reset-player)
  136. (init)
  137. (song! 0)
  138. (reset))))
  139. (fn advance []
  140. (stat-updates entities)
  141. (brains entities)
  142. (if (not (empty? msgs)) (global msgs (rest msgs))))
  143. (global TIC
  144. (fn []
  145. (update-tweens)
  146. (if
  147. (= LOOP :death)
  148. (draw-death)
  149. (do
  150. (draw)
  151. (if (or (dialogue?) _button_dirty)
  152. (set _button_dirty false)
  153. (do
  154. (var change true)
  155. (if
  156. (btnp 0) (walk player (point 0 -1))
  157. (btnp 1) (walk player (point 0 1))
  158. (btnp 2) (walk player (point -1 0))
  159. (btnp 3) (walk player (point 1 0))
  160. (btnp 4) (do (wait 1 (fn [] (sfx 63 "C#4" -1 3) (command-menu)))
  161. (set change false)) ;don't advance game
  162. (btnp 5) (when (= :pass (action player))
  163. (advance))
  164. (set change false))
  165. (when change
  166. (let [t (trigger-at player.pos)]
  167. (if (and t t.store)
  168. (shop t.store)
  169. (do (advance)
  170. (draw)))))))))))
  171. (init)
  172. ;(kill-player)