Use state return-values for overworld loop

This commit is contained in:
Jaidyn Ann 2023-06-09 20:14:31 -05:00
parent 8cbd029d6d
commit 32c95c3725
2 changed files with 15 additions and 14 deletions

View File

@ -96,8 +96,11 @@ or something ¯\_(ツ)_/¯"
(defun make-main-overworld-state ()
"Return a state-function for the games 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 ()

View File

@ -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))