123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- (fn <-town [v] (vadd v (point -30 0)))
- (fn town-wall [t]
- (or (= t 101) (= t 102) (= t 105) (= t 154)
- (= t 97) (= t 144) (= t 160) (= t 153)))
- (fn create-town [] ;30,1 59,16
- (global world (make-map 29 16 1))
- (global tiles (make-map 29 16 0))
- (for [y 1 16]
- (for [x 30 59]
- (let [t (mget x y)]
- (gset tiles (<-town (point x y)) t)
- (when (town-wall t)
- (gset world (<-town (point x y)) 0)))))
- (global entities [player])
- (global items [])
- (global triggers [])
- (tset player :pos (<-town (point 37 10)))
- (populate-dist
- world entities
- (initialize-monster monster-map.townie) 3 player.pos 8)
- (add triggers {:stairs true :dir 1 :pos (<-town (point 53 7))})
- (add triggers {:store :general :pos (<-town (point 36 6))})
- (add triggers {:store :armory :pos (<-town (point 33 12))})
- (add triggers {:store :magic :pos (<-town (point 43 12))}))
- (fn create-level [dir]
- (set DEEPEST (math.max DEEPEST depth))
- ;create a new dungeon world
- ;eventually should take depth params
- (global world (make-map 64 64 0))
- (global tiles (make-map 64 64 0))
- (drunk-dungeon world (point 16 16) 100 1)
- (for [i 1 3]
- (drunk-dungeon world (random-tile world 1) 100 1 30))
- (for [i 1 (roll [1 4])] ;water
- (drunk-dungeon world (random-tile world 1) 20 2 20))
- (map->tiles world tiles (rand-nth
- [themes.stone themes.bright themes.stone themes.bright themes.woods]))
- (global entities [player])
- (global items [])
- (global triggers [])
- (tset player :pos (random-tile world 1))
- (if (= dir 1) ;down
- (place-clone-at up-stair triggers player.pos)
- (= dir -1) ;up
- (place-clone-at down-stair triggers player.pos))
- (let [mobs (filter (fn [o] (and (> o.level 0) (<= o.level depth)) )
- (vals monster-map))
- cnt (+ 2 depth (roll [1 4]))]
- (for [i 1 cnt]
- (populate-dist world entities
- (initialize-monster (rand-nth mobs)) 1 player.pos 8)))
- (if (= depth 10)
- (do
- (populate-dist world entities
- (initialize-monster (. monster-map :ohno)) 1 player.pos 8)
- (place-doors 0 1 player.pos 40))
- (place-doors 2 2 player.pos 40))
- (let [itms (filter (fn [o] (or (<= o.level (inc depth)) (chance 5)))
- (vals item-map))
- cnt (+ 1 depth (roll [1 4]))]
- (for [i 1 10]
- (let [o (initialize-item (rand-nth itms))]
- (populate world items o 1)))))
- (fn hud [v]
- (print (.. "FLOOR " depth) 8 1 6)
- (print (.. "LVL " player.level) 62 1 13)
- (print (.. "$ " (math.floor player.gold)) 100 1 14)
- (print (.. "EXP " (math.floor player.exp) "/" (exp-next player.level)) 160 1 7)
- (print (.. "hp " player.hp "/" player.maxhp) 8 129 9)
- (var action-name "") ;TODO clean this up
- (let [t (trigger-at player.pos)
- i (items-at player.pos)]
- (if
- (not (empty? i))
- (set action-name (.. "get " (. (first i) :name)))
- (and t t.stairs (= t.dir 1))
- (set action-name "descend")
- (and t t.stairs (= t.dir -1))
- (set action-name "ascend")
- (set action-name "wait")))
- (print (or (first msgs) (.. "[z] commands, [x] " action-name)) 70 129)
- (print (.. "equipment" ) v.x (+ v.y 0) 9)
- (spr 208 v.x (+ v.y 8) 0)
- (spr 209 v.x (+ v.y 16) 0)
- (spr 210 v.x (+ v.y 24) 0)
- (when player.equip.head
- (item-print player.equip.head (point (+ v.x 10) (+ v.y 8))))
- (when player.equip.body
- (item-print player.equip.body (point (+ v.x 10) (+ v.y 16))))
- (when player.equip.feet
- (item-print player.equip.feet (point (+ v.x 10) (+ v.y 24))))
- (print (.. "weapon" ) v.x (+ v.y 32) 9)
- (if player.weapon
- (item-print player.weapon (point v.x (+ v.y 40))))
- (print (.. "inventory " ) v.x (+ v.y 48) 9)
- (each [i o (ipairs player.inventory)]
- (item-print o (point (+ v.x 4) (+ v.y 48 (* i 8))))))
- (fn draw []
- (cls 1)
- (clip 8 8 120 120)
- (cls 0)
- (draw-map tiles (->view (point 0 0)) identity)
- (sprites triggers)
- (sprites items)
- (sprites entities)
- (draw-fx)
- (clip)
- ;(print DEBUG)
- (hud (point 132 8))
- (if (dialogue?) ((last _dialogue))))
- (fn center-print [s x y c]
- ;pretend fixed with font
- (print s (- x (* (# s) 4.5 0.5)) y (or c 15)))
- (fn init []
- (set change-level create-level)
- (if quickstart?
- (change-level)
- (create-town))
- (song! 0)
- (draw))
- (fn draw-death [] ;216 232
- (let [v creditsv
- v2 (vadd v (point 0 100))]
- (cls 0)
- (center-print (if DEATHMSG "You have prevailed!" "You have perished..") v.x v.y)
- (spr (if DEATHMSG 218 216) v.x (- v.y 32) 0 1 0 0 2 2)
- (center-print GAMENAME v.x v2.y 6)
- (center-print "2019" (+ v.x 5) (+ v2.y 8) 11)
- (center-print "by" (+ v.x 5) (+ v2.y 40) 8)
- (center-print "selfsame & equa" (+ v.x -2) (+ v2.y 48) 9)
- (center-print "made for Lisp Game Jam" v.x (+ v2.y 100) 12)
- (center-print "(press x to restart)" v.x (+ v2.y 150) 4)
- (when (btnp 5)
- (set LOOP :game)
- (reset-player)
- (init)
- (song! 0)
- (reset))))
- (fn advance []
- (stat-updates entities)
- (brains entities)
- (if (not (empty? msgs)) (global msgs (rest msgs))))
- (global TIC
- (fn []
- (update-tweens)
- (if
- (= LOOP :death)
- (draw-death)
- (do
- (draw)
- (if (or (dialogue?) _button_dirty)
- (set _button_dirty false)
- (do
- (var change true)
- (if
- (btnp 0) (walk player (point 0 -1))
- (btnp 1) (walk player (point 0 1))
- (btnp 2) (walk player (point -1 0))
- (btnp 3) (walk player (point 1 0))
- (btnp 4) (do (wait 1 (fn [] (sfx 63 "C#4" -1 3) (command-menu)))
- (set change false)) ;don't advance game
- (btnp 5) (when (= :pass (action player))
- (advance))
- (set change false))
- (when change
- (let [t (trigger-at player.pos)]
- (if (and t t.store)
- (shop t.store)
- (do (advance)
- (draw)))))))))))
- (init)
- ;(kill-player)
|