9dbe31fef037

Add meat and help
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 07 Jan 2017 18:46:14 +0000
parents fa45164eab85
children 1c92535d2aec
branches/tags (none)
files data/help.txt data/meat.lisp src/entities/food.lisp src/main.lisp src/utilities.lisp

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/help.txt	Sat Jan 07 18:46:14 2017 +0000
@@ -0,0 +1,8 @@
+Summer has begun in the southern hemisphere.
+You must head to the North Pole to survive.
+
+CONTROLS
+←↑↓→ - move
+   q - quit
+   g - get item
+   d - drop item
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/meat.lisp	Sat Jan 07 18:46:14 2017 +0000
@@ -0,0 +1,11 @@
+#("lamb"
+  "chicken"
+  "beef"
+  "mutton"
+  "venison"
+  "pork"
+  "ham"
+  "corned-beef hash"
+  "duck"
+  "turkey"
+  "alligator meat")
--- a/src/entities/food.lisp	Sat Jan 07 17:48:08 2017 +0000
+++ b/src/entities/food.lisp	Sat Jan 07 18:46:14 2017 +0000
@@ -1,7 +1,9 @@
 (in-package :ap.entities)
 
-(defparameter *vegetables*
-  (read-file-into-form "data/vegetables.lisp"))
+(defparameter *foods*
+  (concatenate 'vector
+               (read-file-into-form "data/vegetables.lisp")
+               (read-file-into-form "data/meat.lisp")))
 
 
 (define-entity food (visible coords holdable)
@@ -13,7 +15,7 @@
 (defun random-food-description ()
   (format nil "a ~A of ~A"
           (random-elt #("can" "tin" "package"))
-          (random-elt *vegetables*)))
+          (random-elt *foods*)))
 
 (defun make-food (x y)
   (create-entity 'food
--- a/src/main.lisp	Sat Jan 07 17:48:08 2017 +0000
+++ b/src/main.lisp	Sat Jan 07 18:46:14 2017 +0000
@@ -9,6 +9,7 @@
 (defparameter *intro4* (read-file-into-string "data/intro4.txt"))
 (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 *screen-width* nil)
 (defparameter *screen-height* nil)
@@ -143,6 +144,23 @@
   (world-map))
 
 
+;;;; Popups -------------------------------------------------------------------
+(defun popup (contents)
+  (let ((lines (cl-strings:split contents #\newline)))
+    (with-dims ((+ 3 (apply #'max 13 (mapcar #'length lines)))
+                (+ 3 (length lines)))
+      (with-panel-and-window
+          (pan win *width* *height*
+               (center *width* *screen-width*)
+               (center *height* *screen-height*))
+        (charms:clear-window win)
+        (border win)
+        (write-lines-left win lines 1 1)
+        (write-string-centered win "Press any key" (1- *height*))
+        (redraw)
+        (charms:get-char win)))))
+
+
 ;;;; World Map ----------------------------------------------------------------
 (defun terrain-char (height)
   (cond ((< height -0.20) (values #\~ +blue-black+)) ; deep water
@@ -219,7 +237,8 @@
         (write-lines-left window
                           (cl-strings:shorten (holdable/description item)
                                               (- *width* 2 2 3 1))
-                          3 y)))))
+                          3 y)))
+    (write-string-left window (format nil "Press h for help") 1 (1- *height*))))
 
 
 (defun move-player (dx dy)
@@ -231,6 +250,7 @@
 (defun world-map-input (window)
   (case (charms:get-char window)
     (#\q :quit)
+    (#\h :help)
     (:left  (move-player -1 0) :tick)
     (:right (move-player 1 0) :tick)
     (:up    (move-player 0 -1) :tick)
@@ -250,9 +270,12 @@
           (render-map map-win)
           (render-items map-win))
         (redraw)
-        (case (world-map-input bar-win)
-          (:tick (tick-player *player*))
-          (:quit (return))))))
+        (if-first-time
+          (popup "Head north!")
+          (case (world-map-input bar-win)
+            (:tick (tick-player *player*))
+            (:quit (return))
+            (:help (popup *help*)))))))
   nil)
 
 
--- a/src/utilities.lisp	Sat Jan 07 17:48:08 2017 +0000
+++ b/src/utilities.lisp	Sat Jan 07 18:46:14 2017 +0000
@@ -62,15 +62,19 @@
 (defun write-string-centered (window string y)
   (charms:write-string-at-point window string (center (length string) ap::*width*) y))
 
-(defun write-lines-left (window string start-x start-y)
-  (iterate (for line :in (cl-strings:split string #\newline))
-           (for y :from start-y)
-           (write-string-left window line start-x y)))
+(defun write-lines-left (window contents start-x start-y)
+  (if (stringp contents)
+    (write-lines-left window (cl-strings:split contents #\newline) start-x start-y)
+    (iterate (for line :in contents)
+             (for y :from start-y)
+             (write-string-left window line start-x y))))
 
-(defun write-lines-centered (window string start-y)
-  (iterate (for line :in (cl-strings:split string #\newline))
-           (for y :from start-y)
-           (write-string-centered window line y)))
+(defun write-lines-centered (window contents start-y)
+  (if (stringp contents)
+    (write-lines-centered window (cl-strings:split contents #\newline) start-y)
+    (iterate (for line :in contents)
+             (for y :from start-y)
+             (write-string-centered window line y))))
 
 
 (defmacro with-dims ((width height) &body body)