Run INTERACT function mentioned in Tiled map

This commit is contained in:
Jaidyn Ann 2023-06-16 12:16:44 -05:00
parent c37ce281ea
commit c801a2ddfb
3 changed files with 29 additions and 10 deletions

View File

@ -22,6 +22,7 @@
(load "input.lisp")
(load "display.lisp")
(load "ui.lisp")
(load "tiled.lisp")
(load "overworld.lisp")
(defpackage :flora-search-aurora
@ -33,6 +34,10 @@
(in-package :flora-search-aurora)
(defun talk (map)
(print "AAAAA"))
(defun state-loop
(states &key (last-matrix (make-screen-matrix)) (matrix (make-screen-matrix)) (state-params nil))
"Begin the games loop, which executes (henceforthly called) state-functions over and over again
@ -49,9 +54,8 @@ state-function in the next iteration, in addition to the aforementioned matrix.
If this function returns a function, then the returned function will go to the front of the
state-function list, and will be ran in the next iteration onward.
If this function returns anything else, then itll simply be run again in the next iteration.
Make note to add a delay to your state functions, or well, yknow. Your computer will overheat,
or something ¯\_()_/¯"
Make note to add a delay w SLEEP to your state functions, or well, yknow. Your computer will
overheat, or something ¯\_()_/¯"
(when states
(let ((state-result
(apply (car states) (cons matrix state-params)))) ;; Run the latest-added update/draw loop
@ -69,7 +73,7 @@ or something ¯\_(ツ)_/¯"
(defun make-main-menu-state ()
"Return a state-function for the games main menu, for use with #'state-loop."
"Return a state-function for the games main menu, for use with STATE-LOOP."
(let ((main-menu
`(((LABEL . "PLAY")
(SELECTION . 100) (SELECTED . T)
@ -82,7 +86,7 @@ or something ¯\_(ツ)_/¯"
(defun make-options-menu-state ()
"Return a state-function for the options menu, for use with #'state-loop."
"Return a state-function for the options menu, for use with STATE-LOOP."
(let ((options-menu
`(((LABEL . "IDK")
(SELECTION . 100) (SELECTED . T)
@ -94,8 +98,8 @@ 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."
"Return a state-function for the games overworld (the majority of the game), for use
with STATE-LOOP."
(lambda (matrix &rest args)
(apply #'overworld-state
(append (list matrix)
@ -106,6 +110,7 @@ or something ¯\_(ツ)_/¯"
(defun main ()
"A pathetic fascimile of a main loop. What does it do? WHAST DOES TI DODOO?"
(cl-charms:with-curses ()
(cl-charms/low-level:curs-set 0) ;; Hide the terminal cursor
(cl-charms:enable-raw-input :interpret-control-characters 't)
(clear-screen)
(state-loop (list (make-main-menu-state)))))

View File

@ -65,6 +65,10 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE."
(if (listen)
(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)))
(if interact
(apply (intern interact) (list map)))))
((plist= input '(:modifier nil :char #\→))
(move-entity map 'player :x 1))
((plist= input '(:modifier nil :char #\←))
@ -173,7 +177,7 @@ alist containing a character (:CHAR) and :X & :Y coordinates."
(cond ((eq direction 'right)
(ignore-errors (setf (aref matrix y x) #\|))
(ignore-errors (setf (aref matrix y (- x 1)) #\|)))
((eq direction 'left)
('t
(ignore-errors (setf (aref matrix y x) #\|))
(ignore-errors (setf (aref matrix y (+ x 1)) #\|))))))

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="left-down" width="144" height="40" tilewidth="12" tileheight="17" infinite="0" nextlayerid="10" nextobjectid="3">
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="left-down" width="144" height="40" tilewidth="12" tileheight="17" infinite="0" nextlayerid="10" nextobjectid="5">
<tileset firstgid="1" source="font.tsx"/>
<layer id="1" name="Background" width="144" height="40">
<properties>
@ -98,9 +98,19 @@
<objectgroup id="7" name="Entities">
<object id="2" name="Player" type="Entity" x="103" y="368">
<properties>
<property name="face" value="uwu"/>
<property name="face" value="=w="/>
<property name="facing_right" type="bool" value="true"/>
<property name="id" value="player"/>
<property name="interact" value="TALK"/>
</properties>
<point/>
</object>
<object id="4" name="Literary girl" type="Entity" x="317.604" y="366.606">
<properties>
<property name="face" value="owo"/>
<property name="facing_right" type="bool" value="true"/>
<property name="id" value="literary-girl"/>
<property name="interact" value="flora-search-aurora::interact"/>
</properties>
<point/>
</object>