...
 
Commits (3)
......@@ -3,12 +3,8 @@
(:export #:main))
(in-package :cl-rogue)
;;;; global state --------------------------------------------------------------
(defparameter *width* nil)
(defparameter *height* nil)
(defparameter *scene* nil)
(defparameter *running* nil)
......@@ -28,16 +24,18 @@
(defclass <start-scene> (<scene>) ())
(defmethod display-scene ((s <start-scene>))
(draw-string (window s) (- (floor *width* 2) 7) 2 "CORYS ROGUELIKE")
(draw-string (window s) 0 2 " CORYS ROGUELIKE")
(draw-string (window s) (- (floor *width* 2) 11) 4 "Press [Space] to start")
(draw-string (window s) (- (floor *width* 2) 8) 5 "Press [Q] to quit"))
(draw-string (window s) 0 4 " Press [Space] to start")
(draw-string (window s) 0 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>) ())
......@@ -47,10 +45,10 @@
(draw-string (window s) 0 1 "-- press [Esc] to lose or [Enter] to win --"))
(defmethod handle-input ((s <play-scene>) key)
(when (char= #\Escape key)
(setf *scene* (make-instance '<lose-scene> :window (window s))))
(when (char= #\Newline key)
(setf *scene* (make-instance '<win-scene> :window (window s)))))
(case key
(#\Escape (make-instance '<lose-scene> :window (window s)))
(#\Newline (make-instance '<win-scene> :window (window s)))
(otherwise s)))
(defclass <win-scene> (<scene>) ())
......@@ -60,9 +58,9 @@
(draw-string (window s) 0 1 "-- press [Enter] to restart --"))
(defmethod handle-input ((s <win-scene>) key)
(when (char= #\Newline key)
(setf *scene* (make-instance '<start-scene> :window (window s)))))
(case key
(#\Newline (make-instance '<start-scene> :window (window s)))
(otherwise s)))
(defclass <lose-scene> (<scene>) ())
......@@ -71,8 +69,9 @@
(draw-string (window s) 0 1 "-- press [Enter] to restart --"))
(defmethod handle-input ((s <lose-scene>) key)
(when (char= #\Newline key)
(setf *scene* (make-instance '<start-scene> :window (window s)))))
(case key
(#\Newline (make-instance '<start-scene> :window (window s)))
(otherwise s)))
;;;; drawing --------------------------------------------------------------------
......@@ -83,35 +82,26 @@
x
y))
(defun update-window-dimensions (window)
(multiple-value-bind (width height) (charms:window-dimensions window)
(setf *width* width)
(setf *height* height)))
;;;; main -----------------------------------------------------------------------
(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)))