Newer
Older
naledi / terranostra.lisp
;;;;
;;;; Terra Nostra is a Minecraft-like survival game for the commandline.
;;;;
;;;; This is the main program file.
;;;;
;;;; (c) 2018 Daniel Vedder, MIT license
;;;;


(defvar *debugging* T)

(ql:quickload :croatoan)
(use-package :croatoan)

(load "util.lisp")
(load "items.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 4)) (round (/ height 2)))))
			(with-windows ((mapwin :position '(0 0) :input-blocking t :border t
							   :width (floor (/ width 2)) :height height)
							  (infowin :position (list 0 (floor (/ width 2)))
								  :input-blocking t :border t
								  :width (ceiling (/ width 2)) :height height))
				(draw-map mapwin me)
				(draw-info-panel infowin)
				(event-case (scr event)
					(#\q (return-from event-case))
					(:up (decf (second me)) (draw-map mapwin me))
					(:down (incf (second me)) (draw-map mapwin me))
					(:left (decf (first me)) (draw-map mapwin me))
					(:right (incf (first me)) (draw-map mapwin me)))))))

(defun draw-map (win me)
	"Draw a portion of the game map in an ncurses window"
	;;FIXME
	(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 (- (.width win) 2))
				(let ((p (coord (+ w x0 1) (+ h y0 1))))
					(if (null p) (add-char win #\space)
						;;TODO draw features
						(if (and (= (first (patch-pos p)) (first me))
								(= (second (patch-pos p)) (second me)))
							(progn (setf (.color-pair win) '(:white :black))
								(add-char win #\X))
							(progn
								(setf (.color-pair win)
									(list (biome-col (patch-biome p)) :black))
								(add-char win
									(biome-char (patch-biome p))))))))
			(setf (.cursor-position win) (list (+ h 1) 1))
		(refresh win))))

(defun draw-info-panel (win)
	"Draw the info panel and associated information in an ncurses window"
	;;TODO
	(box win)
	(setf (.cursor-position win) '(1 1))
	(add-string win "This is the information panel.")
	(refresh win))

(defun process-command (event)
	)

;; Initialize the random state (which would otherwise not be very random...)
(setf *random-state* (make-random-state t))

(setf *world* (create-world 100))
(user-interface)