f29a23574bd3

Hack in a starvation warning
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 08 Jan 2017 13:11:40 +0000
parents ab1a74fe819a
children 9aad3f5f030b
branches/tags (none)
files src/config.lisp src/entities/player.lisp src/main.lisp

Changes

--- a/src/config.lisp	Sun Jan 08 12:59:03 2017 +0000
+++ b/src/config.lisp	Sun Jan 08 13:11:40 2017 +0000
@@ -22,6 +22,7 @@
   (+cyan-black+   charms/ll:COLOR_CYAN    charms/ll:COLOR_BLACK)
   (+yellow-black+ charms/ll:COLOR_YELLOW  charms/ll:COLOR_BLACK)
   (+green-black+  charms/ll:COLOR_GREEN   charms/ll:COLOR_BLACK)
+  (+red-black+    charms/ll:COLOR_RED     charms/ll:COLOR_BLACK)
   (+pink-black+   charms/ll:COLOR_MAGENTA charms/ll:COLOR_BLACK)
 
   (+black-white+  charms/ll:COLOR_BLACK charms/ll:COLOR_WHITE)
--- a/src/entities/player.lisp	Sun Jan 08 12:59:03 2017 +0000
+++ b/src/entities/player.lisp	Sun Jan 08 13:11:40 2017 +0000
@@ -12,7 +12,7 @@
 
 (defun energy-description (energy-value)
   (cond ((<= energy-value 0.0) "starving")
-        ((< energy-value 30.0) "famished")
+        ((< energy-value 30.0) "starving")
         ((< energy-value 50.0) "very hungry")
         ((< energy-value 80.0) "hungry")
         ((< energy-value 95.0) "peckish")
--- a/src/main.lisp	Sun Jan 08 12:59:03 2017 +0000
+++ b/src/main.lisp	Sun Jan 08 13:11:40 2017 +0000
@@ -11,6 +11,7 @@
 (defparameter *help* (read-file-into-string "data/help.txt"))
 (defparameter *death* (read-file-into-string "data/death.txt"))
 
+(defparameter *starving-cooldown* 0)
 (defparameter *screen-width* nil)
 (defparameter *screen-height* nil)
 
@@ -504,6 +505,31 @@
            (destroy-entity trigger)))
 
 
+(defun display-starvation-warning ()
+  (with-dims (40 6)
+    (with-panel-and-window
+        (pan win *width* *height*
+             (center *width* *screen-width*)
+             (center *height* *screen-height*))
+      (charms:clear-window win)
+      (border win)
+      (write-string-left win "You are         !" 1 1)
+      (with-color (win +red-black+)
+        (write-string-left win "STARVING" 9 1))
+      (write-string-left win "If you don't eat soon, you will die." 1 3)
+      (write-string-centered win "Press space" (1- *height*))
+      (redraw)
+      (iterate (until (eql #\space (charms:get-char win))))))
+  nil)
+
+(defun check-starvation-warning ()
+  (if (plusp *starving-cooldown*)
+    (progn (decf *starving-cooldown*) nil)
+    (if (< (player/energy *player*) 30.0)
+      (progn (setf *starving-cooldown* 100) t)
+      nil)))
+
+
 (defun world-map ()
   (with-dims ((- *screen-width* 2) (- *screen-height* 1))
     (with-panels-and-windows
@@ -519,15 +545,18 @@
         (redraw)
         (if-first-time
           (popup (format nil "You must head north to survive.~2%You can press h for help in-game."))
-          (cond ((ap.flavor:flavorp)
-                 (popup (ap.flavor:random-flavor)))
-                ((player-dead-p *player*)
-                 (return (death)))
-                (t (case (world-map-input bar-win)
-                     (:tick (tick-player *player*)
-                      (check-triggers))
-                     (:quit (return))
-                     (:help (popup *help*)))))))))
+          (cond
+            ((check-starvation-warning)
+             (display-starvation-warning))
+            ((ap.flavor:flavorp)
+             (popup (ap.flavor:random-flavor)))
+            ((player-dead-p *player*)
+             (return (death)))
+            (t (case (world-map-input bar-win)
+                 (:tick (tick-player *player*)
+                  (check-triggers))
+                 (:quit (return))
+                 (:help (popup *help*)))))))))
   nil)