From 67019e9afbadd7d31137bd6bee2c4846805947f0 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 25 Jun 2023 14:40:12 -0500 Subject: [PATCH] =?UTF-8?q?Moving=20between=20maps:=20Doorways!=20?= =?UTF-8?q?=E2=99=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flora-search-aurora.lisp | 30 ++++++++++++++++++--- overworld.lisp | 57 ++++++++++++++++++++-------------------- res/casino.tmx | 16 +++++------ res/map.tmx | 7 ++++- 4 files changed, 70 insertions(+), 40 deletions(-) diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index 033ae58..444fd99 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -1,4 +1,4 @@ -;;;; Copyright © 2023, Jaidyn Ann + ;;;; Copyright © 2023, Jaidyn Ann ;;;; ;;;; This program is free software: you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License as @@ -48,6 +48,13 @@ `(getf (gethash :knows ,map) ,idea)) + +;;; ——————————————————————————————————— +;;; The Outside World™ +;;; ——————————————————————————————————— +(defparameter *outdoors-map* (overworld.tiled:load-map (format nil "~Ares/map.tmx" (uiop:getcwd)))) + + ;;; ——————————————————————————————————— ;;; Childhood friend (Sasha) arc @@ -126,6 +133,21 @@ (make-dialogue-state map (childhood-friend-dialogue map))) + +;;; ——————————————————————————————————— +;;; Casino! +;;; ——————————————————————————————————— +(defparameter *casino-map* (overworld.tiled:load-map (format nil "~Ares/casino.tmx" (uiop:getcwd)))) + + +(defun casino-entrance-trigger (&optional map) + (list :map *casino-map*)) + + +(defun casino-exit-trigger (&optional map) + (list :map *outdoors-map*)) + + ;;; ——————————————————————————————————— ;;; Random casino NPCs @@ -187,8 +209,10 @@ :face "=w=~")))) -(defun bruh-trigger (&optional map) - (print "YAAAAAAA")) + + + + diff --git a/overworld.lisp b/overworld.lisp index a67bb00..4ebf250 100644 --- a/overworld.lisp +++ b/overworld.lisp @@ -100,6 +100,14 @@ rectangle as defined by its TOP-LEFT-CORNER & BOTTOM-RIGHT-CORNER." (list :x x :y y)))) +(defun trigger-at-coords (map world-coords) + (let ((chunk (world-coords-chunk world-coords))) + (loop for trigger in (cdr (assoc chunk (gethash :triggers map))) + do (when (within-rectangle world-coords + (getf trigger :coords) (getf trigger :bottom-coords)) + (return trigger))))) + + ;;; ——————————————————————————————————— ;;; Overworld logic @@ -127,40 +135,39 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE." ;; ((plist = input '(:modifier nil :char #\Esc))) ;; Simple up-down-left-right movements ((…:plist= input '(:modifier nil :char #\→)) - (move-entity map 'player :x 1) - (list :map map)) + (move-player map :Δx 1)) ((…:plist= input '(:modifier nil :char #\←)) - (move-entity map 'player :x -1) - (list :map map)) + (move-player map :Δx -1)) ((…:plist= input '(:modifier nil :char #\↑)) - (move-entity map 'player :y -1) - (list :map map)) + (move-player map :Δy -1)) ((…:plist= input '(:modifier nil :char #\↓)) - (move-entity map 'player :y 1) - (list :map map)) + (move-player map :Δy 1)) ('t (list :map map)))) (list :map map))) -(defun move-entity (map entity-id &key (x 0) (y 0)) +(defun move-player (map &key (Δx 0) (Δy 0)) + (move-entity map 'player :Δx Δx :Δy Δy) + (let* ((coords (getf-entity-data map 'player :coords)) + (trigger (trigger-at-coords map (list :x (getf coords :x) :y (getf coords :y))))) + (if (and trigger (getf trigger :function)) + (apply (intern (string-upcase (getf trigger :function))) + (list map)) + (list :map map)))) + + + +(defun move-entity (map entity-id &key (Δx 0) (Δy 0)) "Move an entity relative to its current position." - (when (< x 0) + (when (< Δx 0) (setf (getf-entity-data map entity-id :direction) 'left)) - (when (> x 0) + (when (> Δx 0) (setf (getf-entity-data map entity-id :direction) 'right)) (let ((coords (getf-entity-data map entity-id :coords))) (move-entity-to map entity-id - :x (+ x (getf coords :x)) - :y (+ y (getf coords :y))))) - - -(defun trigger-at-coords (map world-coords) - (let ((chunk (world-coords-chunk world-coords))) - (loop for trigger in (cdr (assoc chunk (gethash :triggers map))) - do (when (within-rectangle world-coords - (getf trigger :coords) (getf trigger :bottom-coords)) - (return trigger))))) + :x (+ Δx (getf coords :x)) + :y (+ Δy (getf coords :y))))) (defun move-entity-to (map entity &key (x 0) (y 0)) @@ -179,13 +186,7 @@ Returns parameters to be used in the next invocation of OVERWORLD-STATE." (cdr (getf-entity map entity))) ;; Delete it from the old list… (alexandria:deletef (assoc-utils:aget (gethash :entities map) old-chunk) entity - :test (lambda (id alist) (eq id (car alist))))) - ;; If moving the player-character, check for triggers! (Traps) - (when (eq entity 'player) - (let ((trigger (trigger-at-coords map (list :x x :y y)))) - (if (and trigger (getf trigger :function)) - (apply (intern (string-upcase (getf trigger :function))) - (list map))))))) + :test (lambda (id alist) (eq id (car alist))))))) diff --git a/res/casino.tmx b/res/casino.tmx index 7c0b4b6..de91a87 100644 --- a/res/casino.tmx +++ b/res/casino.tmx @@ -62,8 +62,8 @@ 93,0,0,0,0,0,0,0,93,0,0,93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,93, 93,0,0,0,0,0,0,0,93,0,0,93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,93, 93,0,0,0,0,0,0,0,93,0,0,93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,93, -93,0,64,64,64,64,64,64,16,0,0,93,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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