globals.fnl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. (global GAMENAME "Hats in the Deep")
  2. (var LOOP :game)
  3. (var creditsv (point 110 64))
  4. (var depth 0)
  5. (var change-level (fn []))
  6. (global world [[]])
  7. (global tiles [[]])
  8. (global entities [])
  9. (global items [])
  10. (global triggers [])
  11. (global fx [])
  12. (global msgs [])
  13. (var _song -1)
  14. (var music? true)
  15. (var quickstart? false)
  16. (var GENERAL [])
  17. (var ARMORY [])
  18. (var MAGIC [])
  19. (var DEATHMSG false)
  20. (var DEEPEST 0)
  21. (var cache {})
  22. (fn cache-level []
  23. (tset cache depth {
  24. :world world
  25. :tiles tiles
  26. :entities entities
  27. :items items
  28. :triggers triggers
  29. :playerpos player.pos}))
  30. (fn load-cache [lvl]
  31. (trace "load-cache")
  32. (var c (. cache lvl))
  33. (when c
  34. (trace "LOADING")
  35. (global world c.world)
  36. (global tiles c.tiles)
  37. (global entities c.entities)
  38. (global triggers c.triggers)
  39. (global items c.items)
  40. (set player.pos (copy c.playerpos)))
  41. (if c true false))
  42. (fn clear-cache [] ;remove cached more than 1 depth away from player
  43. (var c {})
  44. (each [k v (pairs cache)]
  45. (if (or (= k 0) ; never uncache town
  46. true ; uncache nothing hahaha
  47. (<= (dec depth) k (inc depth)))
  48. (tset c k v)))
  49. (set cache c))
  50. (fn song! [n]
  51. (when music?
  52. (when (= false (= n _song))
  53. (music n)
  54. (set _song n))))
  55. (fn sound! [k]
  56. (var sound-map {
  57. :levelup 60
  58. :cancel 61
  59. :select 62
  60. :beep 63
  61. :miss 59
  62. :hit 58})
  63. (sfx (. sound-map k) "C#4" -1 3))
  64. (var greystone [128 128 128 128 128 128 128 128 129 129 129 130 131 132 132 132])
  65. (global themes {
  66. :stone {:0 96 :1 greystone :0->1 112 :2 144 :0->2 176 :1->2 160}
  67. :bright {:0 97 :1 greystone :0->1 113 :2 145 :0->2 177 :1->2 161}
  68. :woods {:0 [98 99 100] :1 greystone :0->1 114 :2 146 :0->2 178 :1->2 162}})
  69. (global base-entity {
  70. :pos (point 0 0)
  71. :offset (point 0 0)
  72. :sprite 1
  73. :hp 5
  74. :maxhp 5
  75. :speed 1
  76. :level 1 ;multiplier for a lot of things
  77. :exp 0 ;level benchmark can be calculated
  78. :ac 2 ;lol no clue
  79. :attack [1 2]})
  80. (fn reset-player []
  81. (global player (merge base-entity {
  82. :player true
  83. :sprite 32
  84. :hp 14
  85. :maxhp 14
  86. :gold 24
  87. :inventory []
  88. :inventory-limit 6
  89. :weapon false
  90. :clip-tile true ;stair animation
  91. :equip {
  92. :head false
  93. :body false
  94. :feet false}})))
  95. (reset-player)
  96. (global cardinals [
  97. (point -1 0)
  98. (point 1 0)
  99. (point 0 -1)
  100. (point 0 1)])
  101. (global DEBUG "DEBUG")
  102. (var shop (fn []))