diff --git a/LOGO b/LOGO index 197b474..86d64f5 100644 --- a/LOGO +++ b/LOGO @@ -21,4 +21,3 @@ || NALEDI ya AFRICA - where the adventure began ~ ~ ~ ~ ~ ~ ~ ~|| ============================================================================ - diff --git a/LOGO b/LOGO index 197b474..86d64f5 100644 --- a/LOGO +++ b/LOGO @@ -21,4 +21,3 @@ || NALEDI ya AFRICA - where the adventure began ~ ~ ~ ~ ~ ~ ~ ~|| ============================================================================ - diff --git a/TODO b/TODO index ddd7afa..fffab95 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ NALEDI YA AFRICA - TODO +======================= -Documentation +DOCUMENTATION * strike "rogue-like" from file header, replace with "ncurses-based" @@ -9,14 +10,24 @@ * write game instructions and keyboard shortcuts reference -Game - -* splash screen with game logo +GAME * (I am legion...) -Bugs +BUGS + -> SEVERE + +* The last debug print statement from world creation is only printed after + the UI has been created... + +* The player coordinates (+/- 1) are displayed in the player panel + +* The screen is not automatically redrawn when entering (user-interface) + + + -> HEISENBUGS + * occasionally, scrolling the map will lag, causing an "inertia" effect (reloading resolves this, but what's the cause?) diff --git a/LOGO b/LOGO index 197b474..86d64f5 100644 --- a/LOGO +++ b/LOGO @@ -21,4 +21,3 @@ || NALEDI ya AFRICA - where the adventure began ~ ~ ~ ~ ~ ~ ~ ~|| ============================================================================ - diff --git a/TODO b/TODO index ddd7afa..fffab95 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ NALEDI YA AFRICA - TODO +======================= -Documentation +DOCUMENTATION * strike "rogue-like" from file header, replace with "ncurses-based" @@ -9,14 +10,24 @@ * write game instructions and keyboard shortcuts reference -Game - -* splash screen with game logo +GAME * (I am legion...) -Bugs +BUGS + -> SEVERE + +* The last debug print statement from world creation is only printed after + the UI has been created... + +* The player coordinates (+/- 1) are displayed in the player panel + +* The screen is not automatically redrawn when entering (user-interface) + + + -> HEISENBUGS + * occasionally, scrolling the map will lag, causing an "inertia" effect (reloading resolves this, but what's the cause?) diff --git a/data.lisp b/data.lisp index 23d9e39..c9a3116 100644 --- a/data.lisp +++ b/data.lisp @@ -101,6 +101,7 @@ (defun remove-animal (id) "Remove the animal with this ID from the game" + ;;XXX Can't we just do this with `remove-if'? (do ((al animals (cdr al))) ((null al)) (when (= (.id (car al)) id) diff --git a/LOGO b/LOGO index 197b474..86d64f5 100644 --- a/LOGO +++ b/LOGO @@ -21,4 +21,3 @@ || NALEDI ya AFRICA - where the adventure began ~ ~ ~ ~ ~ ~ ~ ~|| ============================================================================ - diff --git a/TODO b/TODO index ddd7afa..fffab95 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ NALEDI YA AFRICA - TODO +======================= -Documentation +DOCUMENTATION * strike "rogue-like" from file header, replace with "ncurses-based" @@ -9,14 +10,24 @@ * write game instructions and keyboard shortcuts reference -Game - -* splash screen with game logo +GAME * (I am legion...) -Bugs +BUGS + -> SEVERE + +* The last debug print statement from world creation is only printed after + the UI has been created... + +* The player coordinates (+/- 1) are displayed in the player panel + +* The screen is not automatically redrawn when entering (user-interface) + + + -> HEISENBUGS + * occasionally, scrolling the map will lag, causing an "inertia" effect (reloading resolves this, but what's the cause?) diff --git a/data.lisp b/data.lisp index 23d9e39..c9a3116 100644 --- a/data.lisp +++ b/data.lisp @@ -101,6 +101,7 @@ (defun remove-animal (id) "Remove the animal with this ID from the game" + ;;XXX Can't we just do this with `remove-if'? (do ((al animals (cdr al))) ((null al)) (when (= (.id (car al)) id) diff --git a/naledi.lisp b/naledi.lisp index 81b2d0a..06d8c25 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -21,39 +21,59 @@ (load "biomes.lisp") (load "animals.lisp") - -(defun user-interface () - "Create the screen on the ncurses interface and hand over to window functions" - ;;TODO +(defun start-game () (with-screen (scr :input-echoing nil :input-blocking t :enable-colors t :cursor-visibility nil :input-reading :unbuffered) - (let* ((width (.width scr)) (height (1- (.height scr))) - (me (list (round (/ width 4)) (halve height)))) - (with-windows ((mapwin :position '(0 0) :input-blocking t :border t - :width (- width 51) :height height) - (playerwin :position (list 0 (- width 50)) - :input-blocking t :border t - :width 50 :height (halve height 'down)) - (placewin :input-blocking t :border t - :position (list (halve height) (- width 50)) - :width 50 :height (halve height 'down)) - (newswin :input-blocking t - :position (list height 0) - :width width :height 1)) - (update-ui mapwin playerwin placewin newswin me) - (refresh scr) - (event-case (scr event) - (#\q (return-from event-case)) - (#\n (draw-menu (message-window))) - (:up (decf (second me)) (update-ui mapwin playerwin - placewin newswin me)) - (:down (incf (second me)) (update-ui mapwin playerwin - placewin newswin me)) - (:left (decf (first me)) (update-ui mapwin playerwin - placewin newswin me)) - (:right (incf (first me)) (update-ui mapwin playerwin - placewin newswin me)) - (otherwise (notify (string event)))))))) + (splash-screen scr) + (user-interface scr))) + +(defun splash-screen (scr) + "Display the splash screen with the `Naledi ya Africa' logo" + (let* ((width (.width scr)) (height (.height scr)) + (logo (load-text-file "LOGO")) + (y (halve (- height (length logo)))) + (xoff (halve (- width 80)))) + (clear scr) + (dolist (l logo) + (setf (.cursor-position scr) (list y xoff)) + (add-string scr l) + (incf y)) + (setf (.cursor-position scr) (list (1- height) 0)) + (add-string scr "Press any key to continue.") + (event-case (scr event) + (otherwise (return-from event-case))))) + +(defun user-interface (scr) + "Create the screen on the ncurses interface and hand over to window functions" + ;(clear scr) + (let* ((width (.width scr)) (height (1- (.height scr))) + (me (list (round (/ width 4)) (halve height)))) + (with-windows ((mapwin :position '(0 0) :input-blocking t :border t + :width (- width 51) :height height) + (playerwin :position (list 0 (- width 50)) + :input-blocking t :border t + :width 50 :height (halve height 'down)) + (placewin :input-blocking t :border t + :position (list (halve height) (- width 50)) + :width 50 :height (halve height 'down)) + (newswin :input-blocking t + :position (list height 0) + :width width :height 1)) + (update-ui mapwin playerwin placewin newswin me) + ;(refresh scr) + ;;TODO + (event-case (scr event) + (#\q (return-from event-case)) + (#\n (draw-menu (message-window))) + (:up (decf (second me)) (update-ui mapwin playerwin + placewin newswin me)) + (:down (incf (second me)) (update-ui mapwin playerwin + placewin newswin me)) + (:left (decf (first me)) (update-ui mapwin playerwin + placewin newswin me)) + (:right (incf (first me)) (update-ui mapwin playerwin + placewin newswin me)) + (otherwise (notify (string event))))))) (defun update-ui (mapwin playerwin placewin newswin me) "Update all four UI elements" @@ -69,10 +89,10 @@ (setf (.color-pair win) '(:white :black)) (box win) (setf (.cursor-position win) '(1 1)) - (let ((x0 (- (first me) (round (/ (.width win) 2)))) - (y0 (- (second me) (round (/ (.height win) 2))))) - (dotimes (h (- (.height win) 1)) - (dotimes (w (- (floor (/ (.width win) 2)) 1)) + (let ((x0 (- (first me) (halve (.width win)))) + (y0 (- (second me) (halve (.height win))))) + (dotimes (h (1- (.height win))) + (dotimes (w (- (halve (.width win) 'floor) 2)) (let ((p (coord (+ w x0 1) (+ h y0 1)))) (if (null p) (add-char win #\space) (if (and (= (first (patch-pos p)) (first me)) @@ -93,7 +113,7 @@ (add-char win (biome-char (patch-biome p))))))) (add-char win #\space))) - (setf (.cursor-position win) (list (+ h 1) 1))) + (setf (.cursor-position win) (list (1+ h) 1))) (refresh win))) (defun draw-player-panel (win) @@ -156,4 +176,4 @@ (setf *random-state* (make-random-state t)) (create-world 100) -(user-interface) +(start-game) diff --git a/LOGO b/LOGO index 197b474..86d64f5 100644 --- a/LOGO +++ b/LOGO @@ -21,4 +21,3 @@ || NALEDI ya AFRICA - where the adventure began ~ ~ ~ ~ ~ ~ ~ ~|| ============================================================================ - diff --git a/TODO b/TODO index ddd7afa..fffab95 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,7 @@ NALEDI YA AFRICA - TODO +======================= -Documentation +DOCUMENTATION * strike "rogue-like" from file header, replace with "ncurses-based" @@ -9,14 +10,24 @@ * write game instructions and keyboard shortcuts reference -Game - -* splash screen with game logo +GAME * (I am legion...) -Bugs +BUGS + -> SEVERE + +* The last debug print statement from world creation is only printed after + the UI has been created... + +* The player coordinates (+/- 1) are displayed in the player panel + +* The screen is not automatically redrawn when entering (user-interface) + + + -> HEISENBUGS + * occasionally, scrolling the map will lag, causing an "inertia" effect (reloading resolves this, but what's the cause?) diff --git a/data.lisp b/data.lisp index 23d9e39..c9a3116 100644 --- a/data.lisp +++ b/data.lisp @@ -101,6 +101,7 @@ (defun remove-animal (id) "Remove the animal with this ID from the game" + ;;XXX Can't we just do this with `remove-if'? (do ((al animals (cdr al))) ((null al)) (when (= (.id (car al)) id) diff --git a/naledi.lisp b/naledi.lisp index 81b2d0a..06d8c25 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -21,39 +21,59 @@ (load "biomes.lisp") (load "animals.lisp") - -(defun user-interface () - "Create the screen on the ncurses interface and hand over to window functions" - ;;TODO +(defun start-game () (with-screen (scr :input-echoing nil :input-blocking t :enable-colors t :cursor-visibility nil :input-reading :unbuffered) - (let* ((width (.width scr)) (height (1- (.height scr))) - (me (list (round (/ width 4)) (halve height)))) - (with-windows ((mapwin :position '(0 0) :input-blocking t :border t - :width (- width 51) :height height) - (playerwin :position (list 0 (- width 50)) - :input-blocking t :border t - :width 50 :height (halve height 'down)) - (placewin :input-blocking t :border t - :position (list (halve height) (- width 50)) - :width 50 :height (halve height 'down)) - (newswin :input-blocking t - :position (list height 0) - :width width :height 1)) - (update-ui mapwin playerwin placewin newswin me) - (refresh scr) - (event-case (scr event) - (#\q (return-from event-case)) - (#\n (draw-menu (message-window))) - (:up (decf (second me)) (update-ui mapwin playerwin - placewin newswin me)) - (:down (incf (second me)) (update-ui mapwin playerwin - placewin newswin me)) - (:left (decf (first me)) (update-ui mapwin playerwin - placewin newswin me)) - (:right (incf (first me)) (update-ui mapwin playerwin - placewin newswin me)) - (otherwise (notify (string event)))))))) + (splash-screen scr) + (user-interface scr))) + +(defun splash-screen (scr) + "Display the splash screen with the `Naledi ya Africa' logo" + (let* ((width (.width scr)) (height (.height scr)) + (logo (load-text-file "LOGO")) + (y (halve (- height (length logo)))) + (xoff (halve (- width 80)))) + (clear scr) + (dolist (l logo) + (setf (.cursor-position scr) (list y xoff)) + (add-string scr l) + (incf y)) + (setf (.cursor-position scr) (list (1- height) 0)) + (add-string scr "Press any key to continue.") + (event-case (scr event) + (otherwise (return-from event-case))))) + +(defun user-interface (scr) + "Create the screen on the ncurses interface and hand over to window functions" + ;(clear scr) + (let* ((width (.width scr)) (height (1- (.height scr))) + (me (list (round (/ width 4)) (halve height)))) + (with-windows ((mapwin :position '(0 0) :input-blocking t :border t + :width (- width 51) :height height) + (playerwin :position (list 0 (- width 50)) + :input-blocking t :border t + :width 50 :height (halve height 'down)) + (placewin :input-blocking t :border t + :position (list (halve height) (- width 50)) + :width 50 :height (halve height 'down)) + (newswin :input-blocking t + :position (list height 0) + :width width :height 1)) + (update-ui mapwin playerwin placewin newswin me) + ;(refresh scr) + ;;TODO + (event-case (scr event) + (#\q (return-from event-case)) + (#\n (draw-menu (message-window))) + (:up (decf (second me)) (update-ui mapwin playerwin + placewin newswin me)) + (:down (incf (second me)) (update-ui mapwin playerwin + placewin newswin me)) + (:left (decf (first me)) (update-ui mapwin playerwin + placewin newswin me)) + (:right (incf (first me)) (update-ui mapwin playerwin + placewin newswin me)) + (otherwise (notify (string event))))))) (defun update-ui (mapwin playerwin placewin newswin me) "Update all four UI elements" @@ -69,10 +89,10 @@ (setf (.color-pair win) '(:white :black)) (box win) (setf (.cursor-position win) '(1 1)) - (let ((x0 (- (first me) (round (/ (.width win) 2)))) - (y0 (- (second me) (round (/ (.height win) 2))))) - (dotimes (h (- (.height win) 1)) - (dotimes (w (- (floor (/ (.width win) 2)) 1)) + (let ((x0 (- (first me) (halve (.width win)))) + (y0 (- (second me) (halve (.height win))))) + (dotimes (h (1- (.height win))) + (dotimes (w (- (halve (.width win) 'floor) 2)) (let ((p (coord (+ w x0 1) (+ h y0 1)))) (if (null p) (add-char win #\space) (if (and (= (first (patch-pos p)) (first me)) @@ -93,7 +113,7 @@ (add-char win (biome-char (patch-biome p))))))) (add-char win #\space))) - (setf (.cursor-position win) (list (+ h 1) 1))) + (setf (.cursor-position win) (list (1+ h) 1))) (refresh win))) (defun draw-player-panel (win) @@ -156,4 +176,4 @@ (setf *random-state* (make-random-state t)) (create-world 100) -(user-interface) +(start-game) diff --git a/util.lisp b/util.lisp index d6d034c..643512d 100644 --- a/util.lisp +++ b/util.lisp @@ -75,6 +75,7 @@ ;; Some of these functions are probably quite inefficient (lots of consing) (defun remove-first-if (fn lst) + ;;FIXME isn't this identical to `remove-if'? "Remove the first element in a list that satisfies the given predicate" (cond ((null lst) NIL) ((funcall fn (car lst)) (cdr lst))