diff options
| -rw-r--r-- | player.fnl | 5 | ||||
| -rw-r--r-- | world.fnl | 18 |
2 files changed, 16 insertions, 7 deletions
@@ -108,6 +108,7 @@ walking 1 :else 0))) +;; Statefully modifies the animation parameters associated with `player'. (fn update-player-animations [player dt] (when (> 10 (math.abs (. player :y-vel))) (tset player :action :jump false)) @@ -117,7 +118,6 @@ (tset player :animation-y-offset (next-player-animation-y-offset player)) (when (> 0 (. player :animation-timer)) (tset player :animation-timer 0.1))) - ;; Returns a new player object. (fn new-player [] @@ -133,6 +133,9 @@ :x-vel 0 :y-vel 0 + :cur-health 5 + :max-health 5 + :orientation :right :animation-x-offset 0 :animation-y-offset 0 @@ -90,6 +90,17 @@ (when (~= :empty (. tile :type)) (draw-tile tile screen-x screen-y)))))))) +(fn draw-hud [world screen-width screen-height] + (let [cur-health (. world :player :cur-health) + max-health (. world :player :max-health) + font-height (: (love.graphics.getFont) :getHeight) + surfaces-slimed (. world :surfaces-slimed) + surfaces-total (. world :surfaces-total) + health-msg (string.format "h: %d/%d" cur-health max-health) + slime-msg (string.format "s: %d/%d" surfaces-slimed surfaces-total)] + (love.graphics.print health-msg 0 (- screen-height (* 2 font-height))) + (love.graphics.print slime-msg 0 (- screen-height font-height)))) + (fn draw-world [world camera-x camera-y screen-width screen-height] (love.graphics.clear 0.1 0.1 0.1) (draw-map world camera-x camera-y screen-width screen-height) @@ -99,12 +110,7 @@ x (- player-x camera-x) y (- player-y camera-y)] (: player :draw x y)) - ;; TODO: Refactor this into multiple functions - (love.graphics.print (string.format "%d/%d" (. world :surfaces-slimed) - (. world :surfaces-total)) - 0 0)) - - + (draw-hud world screen-width screen-height)) ;; Returns whether or not `tile' exists in `checked'. (fn tile-checked [tile checked] |