948b58e1569a

Add death
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 08 Jan 2017 12:34:16 +0000
parents ae09c71d52e8
children 9c7178abf7db
branches/tags (none)
files data/death.txt package.lisp src/entities/player.lisp src/main.lisp

Changes

diff -r ae09c71d52e8 -r 948b58e1569a data/death.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/death.txt	Sun Jan 08 12:34:16 2017 +0000
@@ -0,0 +1,7 @@
+You fall to the ground, unable to go on.  The
+heat is stifling at first, but gradually you
+stop feeling it.  Eventually you stop feeling
+anything at all.
+
+A warm, inviting light envelops your senses as
+your conciousness fades into nothingness.
diff -r ae09c71d52e8 -r 948b58e1569a package.lisp
--- a/package.lisp	Sun Jan 08 12:25:16 2017 +0000
+++ b/package.lisp	Sun Jan 08 12:34:16 2017 +0000
@@ -53,6 +53,7 @@
     :player-get
     :player-drop
     :player-eat
+    :player-dead-p
 
     :food
     :make-food
diff -r ae09c71d52e8 -r 948b58e1569a src/entities/player.lisp
--- a/src/entities/player.lisp	Sun Jan 08 12:25:16 2017 +0000
+++ b/src/entities/player.lisp	Sun Jan 08 12:34:16 2017 +0000
@@ -36,7 +36,7 @@
 
 (defun tick-player (player)
   (zapf (player/energy player) (clamp 0.0 140.0 (- % 0.3))
-        (player/health player) (clamp 0.0 100.0
+        (player/health player) (clamp -1.0 100.0
                                       (+ % (if (< (player/energy player) 1.0)
                                              -0.5
                                              0.1)))))
@@ -66,3 +66,6 @@
         (food/energy food))
   (removef (player/inventory player) food)
   (destroy-entity food))
+
+(defun player-dead-p (player)
+  (<= (player/health player) 0.0))
diff -r ae09c71d52e8 -r 948b58e1569a src/main.lisp
--- a/src/main.lisp	Sun Jan 08 12:25:16 2017 +0000
+++ b/src/main.lisp	Sun Jan 08 12:34:16 2017 +0000
@@ -9,6 +9,7 @@
 (defparameter *intro5* (read-file-into-string "data/intro5.txt"))
 (defparameter *intro6* (read-file-into-string "data/intro6.txt"))
 (defparameter *help* (read-file-into-string "data/help.txt"))
+(defparameter *death* (read-file-into-string "data/death.txt"))
 
 (defparameter *screen-width* nil)
 (defparameter *screen-height* nil)
@@ -311,6 +312,12 @@
        ,@body)))
 
 
+;;;; Death --------------------------------------------------------------------
+(defun death ()
+  (popup *death*)
+  (popup "Thanks for playing!"))
+
+
 ;;;; World Map ----------------------------------------------------------------
 (defun terrain-char (height)
   (cond ((< height -0.20) (values #\~ +blue-black+)) ; deep water
@@ -485,6 +492,7 @@
            (popup (trigger/text trigger))
            (destroy-entity trigger)))
 
+
 (defun world-map ()
   (with-dims ((- *screen-width* 2) (- *screen-height* 1))
     (with-panels-and-windows
@@ -500,13 +508,15 @@
         (redraw)
         (if-first-time
           (popup (format nil "You must head north to survive.~2%You can press h for help in-game."))
-          (if (ap.flavor:flavorp)
-            (popup (ap.flavor:random-flavor))
-            (case (world-map-input bar-win)
-              (:tick (tick-player *player*)
-                     (check-triggers))
-              (:quit (return))
-              (:help (popup *help*))))))))
+          (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*)))))))))
   nil)