summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze <jakob@memeware.net>2018-10-24 16:50:38 -0400
committerJakob L. Kreuze <jakob@memeware.net>2018-10-24 16:50:38 -0400
commit0cb68be20bc265a2635725cace43a634fdb539da (patch)
tree924d7db900a7404e91a5a0e335023add26dc0b09
parenta3dca42441aa48b789e9730edef4ffb63e4de94c (diff)
Initial HUD implementation
-rw-r--r--player.fnl5
-rw-r--r--world.fnl18
2 files changed, 16 insertions, 7 deletions
diff --git a/player.fnl b/player.fnl
index 058902b..0a1bf1f 100644
--- a/player.fnl
+++ b/player.fnl
@@ -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
diff --git a/world.fnl b/world.fnl
index bde756c..f4a9cce 100644
--- a/world.fnl
+++ b/world.fnl
@@ -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]