91b6c62b6f75

Add intro
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 07 Jan 2017 12:54:06 +0000
parents 34cb41653c41
children 552921869758
branches/tags (none)
files data/intro1.txt data/intro2.txt data/intro3.txt data/intro4.txt data/intro5.txt data/intro6.txt package.lisp src/main.lisp src/utilities.lisp

Changes

diff -r 34cb41653c41 -r 91b6c62b6f75 data/intro1.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/intro1.txt	Sat Jan 07 12:54:06 2017 +0000
@@ -0,0 +1,1 @@
+They tried to warn us.
diff -r 34cb41653c41 -r 91b6c62b6f75 data/intro2.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/intro2.txt	Sat Jan 07 12:54:06 2017 +0000
@@ -0,0 +1,3 @@
+For decades scientists told us we were changing
+the climate of our planet.  They warned us that
+if we continued we'd cause irreparable damage.
diff -r 34cb41653c41 -r 91b6c62b6f75 data/intro3.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/intro3.txt	Sat Jan 07 12:54:06 2017 +0000
@@ -0,0 +1,1 @@
+We didn't listen.
diff -r 34cb41653c41 -r 91b6c62b6f75 data/intro4.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/intro4.txt	Sat Jan 07 12:54:06 2017 +0000
@@ -0,0 +1,7 @@
+By the time we started to feel the effects it
+was too late.
+
+Earth was caught in the same spiral Venus
+experienced billions of years ago.  The global
+temperature rose twenty degrees and species
+after species fell to extinction.
diff -r 34cb41653c41 -r 91b6c62b6f75 data/intro5.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/intro5.txt	Sat Jan 07 12:54:06 2017 +0000
@@ -0,0 +1,2 @@
+Thirty years after the spiral begun, you are one
+of the few humans left on the planet.
diff -r 34cb41653c41 -r 91b6c62b6f75 data/intro6.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/intro6.txt	Sat Jan 07 12:54:06 2017 +0000
@@ -0,0 +1,5 @@
+The only habitable places left are the North and
+South poles during their respective winters.
+
+Twice each a year the surviving human population
+must migrate to the opposing pole to stay alive.
diff -r 34cb41653c41 -r 91b6c62b6f75 package.lisp
--- a/package.lisp	Sat Jan 07 12:10:22 2017 +0000
+++ b/package.lisp	Sat Jan 07 12:54:06 2017 +0000
@@ -17,6 +17,7 @@
     :border
     :redraw
     :write-string-left
+    :write-string-right
     :write-string-centered
     :write-lines-left
     :write-lines-centered
diff -r 34cb41653c41 -r 91b6c62b6f75 src/main.lisp
--- a/src/main.lisp	Sat Jan 07 12:10:22 2017 +0000
+++ b/src/main.lisp	Sat Jan 07 12:54:06 2017 +0000
@@ -3,6 +3,12 @@
 
 ;;;; Data ---------------------------------------------------------------------
 (defparameter *logo* (read-file-into-string "data/logo.txt"))
+(defparameter *intro1* (read-file-into-string "data/intro1.txt"))
+(defparameter *intro2* (read-file-into-string "data/intro2.txt"))
+(defparameter *intro3* (read-file-into-string "data/intro3.txt"))
+(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 *screen-width* nil)
 (defparameter *screen-height* nil)
@@ -11,7 +17,52 @@
 (defparameter *height* nil)
 
 
-;;;; State Machine ------------------------------------------------------------
+;;;; Intro --------------------------------------------------------------------
+(defmacro dialog (&body body)
+  `(with-dims (50 10)
+     (with-panel-and-window
+         (pan win *width* *height*
+              (center *width* *screen-width*)
+              (center *height* *screen-height*))
+       (charms:clear-window win)
+       (border win)
+       ,@body
+       (write-string-right win "Press any key" -1 (1- *height*))
+       (redraw)
+       (charms:get-char win))))
+
+(defun intro1 ()
+  (if (eq :left (dialog (write-lines-left win *intro1* 1 1)))
+    (title)
+    (intro2)))
+
+(defun intro2 ()
+  (if (eq :left (dialog (write-lines-left win *intro2* 1 1)))
+    (intro1)
+    (intro3)))
+
+(defun intro3 ()
+  (if (eq :left (dialog (write-lines-left win *intro3* 1 1)))
+    (intro2)
+    (intro4)))
+
+(defun intro4 ()
+  (if (eq :left (dialog (write-lines-left win *intro4* 1 1)))
+    (intro3)
+    (intro5)))
+
+(defun intro5 ()
+  (if (eq :left (dialog (write-lines-left win *intro5* 1 1)))
+    (intro4)
+    (intro6)))
+
+(defun intro6 ()
+  (if (eq :left (dialog (write-lines-left win *intro6* 1 1)))
+    (intro5)
+    nil))
+
+
+;;;; Title --------------------------------------------------------------------
 (defun title ()
   (with-dims (50 10)
     (with-panel-and-window
@@ -20,7 +71,8 @@
              (center *height* *screen-height*))
       (write-lines-centered win *logo* 0)
       (redraw)
-      (charms:get-char win))))
+      (charms:get-char win))
+    (intro1)))
 
 
 ;;;; Main ---------------------------------------------------------------------
diff -r 34cb41653c41 -r 91b6c62b6f75 src/utilities.lisp
--- a/src/utilities.lisp	Sat Jan 07 12:10:22 2017 +0000
+++ b/src/utilities.lisp	Sat Jan 07 12:54:06 2017 +0000
@@ -3,6 +3,7 @@
 ;;;; Charms -------------------------------------------------------------------
 (defmacro with-window ((symbol width height x y) &body body)
   `(let ((,symbol (charms:make-window ,width ,height ,x ,y)))
+     (charms:enable-extra-keys ,symbol)
      (unwind-protect (progn ,@body)
        (charms:destroy-window ,symbol))))
 
@@ -52,8 +53,14 @@
 (defun write-string-left (window string x y)
   (charms:write-string-at-point window string x y))
 
+(defun write-string-right (window string x-offset y)
+  (charms:write-string-at-point
+    window string
+    (- ap::*width* (length string) (abs x-offset))
+    y))
+
 (defun write-string-centered (window string y)
-  (charms:write-string-at-point window string (center (length string) *width*) 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))