From 32c95c37258f888241ce38794868e045e8bbf136 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 9 Jun 2023 20:14:31 -0500 Subject: [PATCH] Use state return-values for overworld loop --- flora-search-aurora.lisp | 7 +++++-- overworld.lisp | 22 ++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index 3b2bb59..56d1768 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -96,8 +96,11 @@ or something ¯\_(ツ)_/¯" (defun make-main-overworld-state () "Return a state-function for the game’s overworld (the majority of the game), for use with #'state-loop." - (lambda (matrix) - (overworld-state matrix "/home/jaidyn/.local/src/games/flora search aurora/res/map.tmx"))) + (lambda (matrix &rest args) + (apply #'overworld-state + (append (list matrix) + '(:map-path #p"/home/jaidyn/.local/src/games/flora search aurora/res/map.tmx") + args)))) (defun main () diff --git a/overworld.lisp b/overworld.lisp index 7db4586..15eb278 100644 --- a/overworld.lisp +++ b/overworld.lisp @@ -30,27 +30,25 @@ ;;; ——————————————————————————————————— ;;; Overworld loop ;;; ——————————————————————————————————— -(defun overworld-state (matrix map) +(defun overworld-state (matrix &key (map-path nil) (map nil) (entity-data nil)) "Render the given map to the matrix and take user-input — for one frame. A state-function for use with #'state-loop." - (let ((map (if (or (stringp map) (pathnamep map)) - (cl-tiled:load-map map) - map))) - (sleep .02) - (overworld-state-draw matrix map) - (overworld-state-update map))) + (sleep .02) + (let ((map (if (not map) (cl-tiled:load-map map-path) map))) + (overworld-state-draw matrix map entity-data) + (overworld-state-update map entity-data))) -(defun overworld-state-draw (matrix map) +(defun overworld-state-draw (matrix map entity-data) "Draw the overworld map to the given matrix. A core part of #'overworld-state." (matrix-write-tiled-map matrix map)) -(defun overworld-state-update (map) - "Do nothing, lol. -Core part of #'overworld-state." - 't) +(defun overworld-state-update (map entity-data) + "Do nothing, lol. Core part of #'overworld-state. +Returns parameters to be used in the next invocation of #'overworld-state." + (list :map map :entity-data entity-data))