8961421a3c9b

Let the player move
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 07 Jan 2017 16:32:09 +0000
parents 4922d66cbba5
children f17271ef79b7
branches/tags (none)
files package.lisp src/main.lisp

Changes

diff -r 4922d66cbba5 -r 8961421a3c9b package.lisp
--- a/package.lisp	Sat Jan 07 16:26:29 2017 +0000
+++ b/package.lisp	Sat Jan 07 16:32:09 2017 +0000
@@ -60,6 +60,7 @@
     :coords/y
     :coords?
     :coords-lookup
+    :coords-move-entity
 
     :visible
     :visible?
diff -r 4922d66cbba5 -r 8961421a3c9b src/main.lisp
--- a/src/main.lisp	Sat Jan 07 16:26:29 2017 +0000
+++ b/src/main.lisp	Sat Jan 07 16:32:09 2017 +0000
@@ -109,6 +109,7 @@
 
 ;;;; World Generation ---------------------------------------------------------
 (defun generate-world ()
+  (clear-entities)
   (with-dims (30 (+ 2 2))
     (with-panel-and-window
         (pan win *width* *height*
@@ -165,6 +166,7 @@
       (with-color (window (visible/color entity))
         (charms:write-string-at-point window (visible/glyph entity) sx sy)))))
 
+
 (defun render-sidebar (window)
   (charms:clear-window window)
   (border window)
@@ -178,13 +180,20 @@
                      1 2))
 
 
+(defun move-player (dx dy)
+  (let ((player *player*))
+    (coords-move-entity player
+                        (+ (coords/x player) dx)
+                        (+ (coords/y player) dy))))
+
 (defun world-map-input (window)
   (case (charms:get-char window)
     (#\q :quit)
-    (:left  (zapf *view-x* (clamp (1- %) 0 20000)))
-    (:right (zapf *view-x* (clamp (1+ %) 0 20000)))
-    (:up    (zapf *view-y* (clamp (1- %) 0 20000)))
-    (:down  (zapf *view-y* (clamp (1+ %) 0 20000)))))
+    (:left (move-player -1 0))
+    (:right (move-player 1 0))
+    (:up    (move-player 0 -1))
+    (:down  (move-player 0 1))))
+
 
 (defun world-map ()
   (with-dims ((- *screen-width* 2) (- *screen-height* 1))