Implemented a rudimentary ncurses map interface.
1 parent 449a5b8 commit 13d6666ccb089caec5dd2b6fa0b30ec1722d90cd
@Daniel Vedder Daniel Vedder authored on 7 Nov 2018
Showing 2 changed files
View
57
terranostra.lisp
 
 
(defvar *debugging* T)
 
(ql:quickload :croatoan)
(use-package :croatoan)
 
(load "util.lisp")
(load "items.lisp")
(load "biome.lisp")
(load "biomes.lisp")
(load "animals.lisp")
(load "world.lisp")
 
 
(defun user-interface ()
"Create the screen on the ncurses interface and hand over to window functions"
;;TODO
(with-screen (scr :input-echoing nil :input-blocking t :enable-colors t
:cursor-visibility nil :input-reading :unbuffered)
(let* ((width (.width scr)) (height (.height scr))
(me (list (round (/ width 2)) (round (/ height 2)))))
(setf (.color-pair scr) '(:green :black))
(draw-test-map scr height width me)
;(draw-map (floor (/ w 2)) h)
;(draw-info-panel (ceiling (/ w 2) h))
(event-case (scr event)
(#\q (return-from event-case))
(:up (decf (second me)) (draw-test-map scr height width me))
(:down (incf (second me)) (draw-test-map scr height width me))
(:left (decf (first me)) (draw-test-map scr height width me))
(:right (incf (first me)) (draw-test-map scr height width me))))))
 
(defun draw-test-map (scr height width me)
(clear scr)
(box scr)
(dotimes (h height)
(dotimes (w width)
(if (and (= w (first me)) (= h (second me)))
(progn (setf (.color-pair scr) '(:white :black))
(add-char scr #\X)
(setf (.color-pair scr) '(:green :black)))
(add-char scr #\;)))
(new-line scr))
(refresh scr))
 
 
;;;FIXME my croatoan version doesn't have `with-window` yet, for some reason...
;; (defun draw-map (width height)
;; "Draw a portion of the game map in an ncurses window"
;; ;;TODO
;; (with-window (mapwin :position '(0 0) :width width :height height
;; :cursor-position '(0 0) :input-blocking t :border t)
;; (dotimes (h height)
;; (add mapwin #\. :n -1))))
 
;; (defun draw-info-panel (width height)
;; "Draw the info panel and associated information in an ncurses window"
;; ;;TODO
;; )
 
(defun process-command (event)
)
 
;; Initialize the random state (which would otherwise not be very random...)
(setf *random-state* (make-random-state t))
 
(create-world 100 "test.world")
;(create-world 100 "test.world")
 
(user-interface)
View
6
world.lisp
(patch (coord x0 y0 world) (neighbour patch dir world)))
((or (null patch) (eq (patch-biome patch) (get-biome 'stream))))
(setf (patch-biome patch) (get-biome 'stream))))
 
(defun create-world (size &optional name (world *world*))
(defun create-world (size &optional (world *world*))
(setf world NIL)
(setf world (init-matrix size))
;;XXX magic numbers
(generate-biomes 20 world)
(dotimes (s (round (/ (expt size 2) 500)))
(generate-stream (random size) (random size) world))
(when name (save-topography name world)))
(generate-stream (random size) (random size) world)))