# HG changeset patch # User Steve Losh # Date 1483881100 0 # Node ID f29a23574bd3f2338ef1b44750a10f0dc2fbad4d # Parent ab1a74fe819abd55c751f8c527812fe66601331a Hack in a starvation warning diff -r ab1a74fe819a -r f29a23574bd3 src/config.lisp --- 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) diff -r ab1a74fe819a -r f29a23574bd3 src/entities/player.lisp --- 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") diff -r ab1a74fe819a -r f29a23574bd3 src/main.lisp --- 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)