diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index ce1ada6..2a2ca1a 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -35,7 +35,9 @@ (defun talk (map) - (print "AAAAA")) + (print (gethash :mom map)) + (setf (gethash :mom map) 3434)) + (defun state-loop diff --git a/overworld.lisp b/overworld.lisp index 030250a..7dcb39b 100644 --- a/overworld.lisp +++ b/overworld.lisp @@ -43,7 +43,7 @@ A state-function for use with STATE-LOOP." (defun overworld-state-draw (matrix map) "Draw the overworld map to the given matrix. A core part of OVERWORLD-STATE." - (let* ((player-data (cdr (assoc 'player (getf map :entities)))) + (let* ((player-data (cdr (assoc 'player (gethash :entities map)))) (chunk (world-coords-chunk (getf player-data :coords)))) (matrix-write-map-chunk matrix map chunk) (matrix-write-entities matrix map))) @@ -66,7 +66,8 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE." (let* ((input (normalize-char-plist (read-char-plist)))) (cond ((plist= input '(:modifier nil :char #\return)) - (let ((interact (getf (cdr (assoc 'player (getf map :entities))) :interact))) + (let ((interact (getf (cdr (assoc 'player (gethash :entities map))) + :interact))) (if interact (apply (intern interact) (list map))))) ((plist= input '(:modifier nil :char #\→)) @@ -81,7 +82,7 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE." (defun move-entity (map entity &key (x 0) (y 0)) "Move an entity relative to its current position." - (let ((entity-plist (cdr (assoc entity (getf map :entities))))) + (let ((entity-plist (cdr (assoc entity (gethash :entities map))))) (when (< x 0) (setf (getf entity-plist :direction) 'left)) (when (> x 0) @@ -93,7 +94,7 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE." (defun move-entity-to (map entity &key (x 0) (y 0)) "Move the given entity to the given coordinates." - (let ((entity-plist (cdr (assoc entity (getf map :entities))))) + (let ((entity-plist (cdr (assoc entity (gethash :entities map))))) (when (walkable-tile-p map x y) (setf (getf (getf entity-plist :coords) :x) x) (setf (getf (getf entity-plist :coords) :y) y)))) @@ -106,9 +107,9 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE." (defun matrix-write-map-chunk (matrix map chunk &key (chunk-width 72) (chunk-height 20)) "Draw a map’s specific chunk (by its ID) to the matrix." - (mapcar (lambda (cell) + (mapcar (lambda (cell) (matrix-write-cell matrix cell)) - (cdr (assoc chunk (getf map :tiles))))) + (cdr (assoc chunk (gethash :tiles map))))) (defun matrix-write-cell (matrix cell) @@ -131,7 +132,7 @@ alist containing a character (:CHAR) and :X & :Y coordinates." (defun walkable-tile-p (map x y) "Return whether or not the given coordinates on the map are traversable for an entity." - (not (cell-at-world-coords-p (getf map :bump-map) + (not (cell-at-world-coords-p (gethash :bump-map map) (list :x x :y y)))) @@ -143,7 +144,7 @@ alist containing a character (:CHAR) and :X & :Y coordinates." "Draw all entities from an alist of entities to the matrix." (mapcar (lambda (entity-assoc) (matrix-write-entity matrix (cdr entity-assoc))) - (getf map :entities))) + (gethash :entities map))) (defun matrix-write-entity (matrix entity-plist) diff --git a/tiled.lisp b/tiled.lisp index 8093448..0f3ffcb 100644 --- a/tiled.lisp +++ b/tiled.lisp @@ -35,7 +35,8 @@ :ENTITIES, a list of entity plists." (let ((tile-chunks '()) (bump-map '()) - (entities '())) + (entities '()) + (hash (make-hash-table))) (mapcar (lambda (layer) (typecase layer (cl-tiled.data-types:tile-layer @@ -45,18 +46,10 @@ (cl-tiled.data-types:object-layer (setf entities (object-layer-entities layer entities))))) (cl-tiled:map-layers (cl-tiled:load-map map-file))) - (list :tiles tile-chunks :bump-map bump-map :entities entities))) - - -(defun tile-layer-chunks (layer &optional (chunks '())) - "Given a Tiled tile-layer (that is, graphics of the map), parse it into an -alist of Tiled cell “chunks”." - (let ((cells (mapcar #'tiled-cell->cell (cl-tiled:layer-cells layer)))) - (collect-items-into-groups - cells - (lambda (cell) - (world-coords-chunk (getf cell :coords))) - :groups chunks))) + (setf (gethash :tiles hash) tile-chunks) + (setf (gethash :bump-map hash) bump-map) + (setf (gethash :entities hash) entities) + hash)) (defun object-layer-entities (layer &optional (entities '())) @@ -79,11 +72,23 @@ alist of Tiled cell “chunks”." :y (floor (/ (cl-tiled:object-y tiled-obj) (cl-tiled:map-tile-height tiled-map)))) :face (gethash "face" properties #'string-equal) + :interact (gethash "interact" properties #'string-equal) :direction (if (gethash "facing_right" properties #'string-equal) 'right 'left)))) +(defun tile-layer-chunks (layer &optional (chunks '())) + "Given a Tiled tile-layer (that is, graphics of the map), parse it into an +alist of Tiled cell “chunks”." + (let ((cells (mapcar #'tiled-cell->cell (cl-tiled:layer-cells layer)))) + (collect-items-into-groups + cells + (lambda (cell) + (world-coords-chunk (getf cell :coords))) + :groups chunks))) + + (defun tiled-cell->cell (tiled-cell) "Convert a Tiled cell into a cell plist." (list :coords (list :x (cl-tiled:cell-column tiled-cell)