diff --git a/terranostra.lisp b/terranostra.lisp new file mode 100644 index 0000000..dc73ebd --- /dev/null +++ b/terranostra.lisp @@ -0,0 +1,27 @@ +#!/usr/bin/clisp +;;;; +;;;; Terra Nostra is a Minecraft-like survival game for the commandline. +;;;; +;;;; (c) 2018 Daniel Vedder +;;;; + +(defvar *world* NIL) + +(defstruct patch + (pos '(0 0)) ;position + (alt 0) ;altitude + (streams-in NIL) + (streams-out NIL)) + +(defun init-matrix (size) + "Create a square matrix of empty patches" + (do ((y 0 (1+ y)) (world NIL) (row NIL NIL)) + ((= y size) world) + (dotimes (x size) + (setf row (append row (list (make-patch :pos (list x y)))))) + (setf world (append world (list row))))) + +(defun coord (x y &optional (world *world*)) + "Return the patch at the given coordinates or NIL if out of bounds" + (unless (or (< x 0) (< y 0) (> x (length world)) (> y (length world))) + (nth x (nth y world))))