Interact with nearby entities

This commit is contained in:
Jaidyn Ann 2023-06-16 14:28:41 -05:00
parent 0f512e80ea
commit b31446c0f1
3 changed files with 35 additions and 9 deletions

View File

@ -34,9 +34,9 @@
(in-package :flora-search-aurora) (in-package :flora-search-aurora)
(defun talk (map) (defun literary-girl-dialogue (map)
(print (gethash :mom map)) (print "uwu"))
(setf (gethash :mom map) 3434))

View File

@ -65,11 +65,14 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE."
(if (listen) (if (listen)
(let* ((input (normalize-char-plist (read-char-plist)))) (let* ((input (normalize-char-plist (read-char-plist))))
(cond (cond
;; Interacting with nearby characters/entities
((plist= input '(:modifier nil :char #\return)) ((plist= input '(:modifier nil :char #\return))
(let ((interact (getf (cdr (assoc 'player (gethash :entities map))) (let* ((player (assoc 'player (gethash :entities map)))
:interact))) (interactee (car (entities-near-entity player (gethash :entities map))))
(if interact (interaction (getf (cdr interactee) :interact)))
(apply (intern interact) (list map))))) (if interaction
(apply (intern (string-upcase interaction)) (list map)))))
;; Simple up-down-left-right movements
((plist= input '(:modifier nil :char #\→)) ((plist= input '(:modifier nil :char #\→))
(move-entity map 'player :x 1)) (move-entity map 'player :x 1))
((plist= input '(:modifier nil :char #\←)) ((plist= input '(:modifier nil :char #\←))
@ -187,6 +190,30 @@ alist containing a character (:CHAR) and :X & :Y coordinates."
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
;;; Misc. utility ;;; Misc. utility
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
(defun entities-near-coords (coords radius entities &key (x-radius radius) (y-radius radius))
(remove-if-not
(lambda (test-entity)
(let ((test-coords (getf (cdr test-entity) :coords)))
(and (< (abs (- (getf coords :x)
(getf test-coords :x)))
x-radius)
(< (abs (- (getf coords :y)
(getf test-coords :y)))
y-radius))))
entities))
(defun entities-near-entity (entity entities)
(remove-if
(lambda (test-entity)
(plist= (cdr entity)
(cdr test-entity)))
(entities-near-coords (getf (cdr entity) :coords)
(+ (length (getf (cdr entity) :face)) 2)
entities
:y-radius 2)))
(defun every-other-element (list) (defun every-other-element (list)
"Collect every-other-element of a list. E.g., (1 2 3 4) → (1 3)." "Collect every-other-element of a list. E.g., (1 2 3 4) → (1 3)."
(when list (when list

View File

@ -101,7 +101,6 @@
<property name="face" value="=w="/> <property name="face" value="=w="/>
<property name="facing_right" type="bool" value="true"/> <property name="facing_right" type="bool" value="true"/>
<property name="id" value="player"/> <property name="id" value="player"/>
<property name="interact" value="TALK"/>
</properties> </properties>
<point/> <point/>
</object> </object>
@ -110,7 +109,7 @@
<property name="face" value="owo"/> <property name="face" value="owo"/>
<property name="facing_right" type="bool" value="true"/> <property name="facing_right" type="bool" value="true"/>
<property name="id" value="literary-girl"/> <property name="id" value="literary-girl"/>
<property name="interact" value="flora-search-aurora::interact"/> <property name="interact" value="literary-girl-dialogue"/>
</properties> </properties>
<point/> <point/>
</object> </object>