Commit 0893ddb6 authored by Cory Chamblin's avatar Cory Chamblin

scrolling

parent 6c44bce8
......@@ -38,11 +38,15 @@
((world
:initarg :world
:initform (error "`world` is required")
:accessor world)))
:accessor world)
(location
:initform '(0 0)
:accessor location)))
(defmethod display-scene ((s <play-scene>) window)
(draw-world window (world s))
(draw-string window 0 (1- *height*) "-- press [Esc] to lose, [Enter] to win, [S] to smooth -- "))
(draw-world window (world s) (location s))
(draw-string window 0 (1- *height*) "-- [~S] press [Esc] to lose, [Enter] to win, [S] to smooth -- " (location s)))
(defmethod handle-input ((s <play-scene>) key)
(case key
......@@ -51,8 +55,16 @@
(#\S (progn
(setf (world s) (smooth (world s)))
s))
(#\l (update-position s :dx 1))
(#\h (update-position s :dx -1))
(#\j (update-position s :dy 1))
(#\k (update-position s :dy -1))
(otherwise s)))
(defun update-position (scene &key (dy 0) (dx 0))
(destructuring-bind (x y) (location scene)
(setf (location scene) (list (+ dx x) (+ dy y))))
scene)
(defclass <win-scene> (<scene>) ())
......@@ -131,11 +143,11 @@
(handler-case (aref world y x)
(sb-int:invalid-array-index-error () (gethash 'bound *tiles*))))
(defun draw-world (window world)
(loop for y upto (1- *height*) do
(loop for x upto (1- (1- *width*)) do
(draw-string window x y (tile-glyph (get-tile world x y))))))
(defun draw-world (window world location)
(destructuring-bind (viewport-x viewport-y) location
(loop for y upto (1- *height*) do
(loop for x upto (1- (1- *width*)) do
(draw-string window x y (tile-glyph (get-tile world (+ viewport-x x) (+ viewport-y y))))))))
;;;; main -----------------------------------------------------------------------
......@@ -161,4 +173,4 @@
(charms:disable-echoing)
(charms:enable-raw-input :interpret-control-characters t)
(gameloop)))
(main)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment