Commit 7ed9db5b authored by Cory Chamblin's avatar Cory Chamblin
Browse files

Made `scene` local

parent ce8c9b40
......@@ -3,12 +3,10 @@
(:export #:main))
(in-package :cl-rogue)
;;;; global state --------------------------------------------------------------
(defparameter *width* nil)
(defparameter *height* nil)
(defparameter *scene* nil)
(defparameter *running* nil)
......@@ -34,10 +32,12 @@
(draw-string (window s) (- (floor *width* 2) 8) 5 "Press [Q] to quit"))
(defmethod handle-input ((s <start-scene>) key)
(when (char= #\Space key)
(setf *scene* (make-instance '<play-scene> :window (window s))))
(when (char= #\Q key)
(setf *running* nil)))
(case key
(#\Space (make-instance '<play-scene> :window (window s)))
(#\Q (progn
(setf *running* nil)
s))
(otherwise s)))
(defclass <play-scene> (<scene>) ())
......@@ -48,9 +48,9 @@
(defmethod handle-input ((s <play-scene>) key)
(when (char= #\Escape key)
(setf *scene* (make-instance '<lose-scene> :window (window s))))
(make-instance '<lose-scene> :window (window s)))
(when (char= #\Newline key)
(setf *scene* (make-instance '<win-scene> :window (window s)))))
(make-instance '<win-scene> :window (window s))))
(defclass <win-scene> (<scene>) ())
......@@ -61,7 +61,7 @@
(defmethod handle-input ((s <win-scene>) key)
(when (char= #\Newline key)
(setf *scene* (make-instance '<start-scene> :window (window s)))))
(make-instance '<start-scene> :window (window s))))
(defclass <lose-scene> (<scene>) ())
......@@ -72,7 +72,7 @@
(defmethod handle-input ((s <lose-scene>) key)
(when (char= #\Newline key)
(setf *scene* (make-instance '<start-scene> :window (window s)))))
(make-instance '<start-scene> :window (window s))))
;;;; drawing --------------------------------------------------------------------
......@@ -94,24 +94,22 @@
(defun initialize (window)
(update-window-dimensions window)
(setf *running* t)
(setf *scene* (make-instance '<start-scene>
:window window)))
(defun render (window)
(charms:clear-window window)
(display-scene *scene*))
(make-instance '<start-scene>
:window window))
(defun gameloop ()
(let ((window charms:*standard-window*))
(initialize window)
(let* ((window charms:*standard-window*)
(scene (initialize window)))
(loop named :game-loop
while *running*
do (progn
(render window)
(handle-input *scene* (charms:get-char window :ignore-error t))))))
(charms:clear-window window)
(display-scene scene)
(setf scene (handle-input scene (charms:get-char window :ignore-error t)))))))
(defun main ()
(charms:with-curses ()
(charms:disable-echoing)
(charms:enable-raw-input :interpret-control-characters t)
(gameloop)))
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