From 94335468b355a38cbdf8080d0a277d8c933f5509 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 9 Jun 2023 07:07:28 -0500 Subject: [PATCH] Begin overworld-rendering loop It draws to the screen, now! Err, well, it has been able to do that, since my first day on this project. But until now, there wasn't a menu leading you there! c:< --- display.lisp | 48 ++++----------------- flora-search-aurora.lisp | 20 ++++----- overworld.lisp | 93 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 50 deletions(-) create mode 100644 overworld.lisp diff --git a/display.lisp b/display.lisp index 52e3e69..1dc2736 100644 --- a/display.lisp +++ b/display.lisp @@ -18,7 +18,8 @@ (defpackage :flora-search-aurora.display (:use :cl) - (:export #:make-screen-matrix #:print-screen-matrix #:screen-matrix-set-map)) + (:export #:make-screen-matrix #:print-screen-matrix #:matrix-delta + #:clear-screen)) (in-package :flora-search-aurora.display) @@ -65,7 +66,9 @@ that change between a→b (favouring those in b) — all others are nil." (do-for-cell matrix (when (characterp cell) (move-cursor (+ i 1) (+ j 1)) - (write-char cell)))) + (write-char cell))) + (destructuring-bind (i j) (array-dimensions matrix) + (move-cursor i j))) (defun make-screen-matrix () @@ -74,43 +77,10 @@ that change between a→b (favouring those in b) — all others are nil." (make-array '(20 72) :initial-element #\space)) -(defun screen-matrix-set-char-cell (matrix cell) - "Set a matrice's (2d array's) element corresponding to -a Tiled cell's character-value, using it's column and row." - (setf (aref matrix - (cl-tiled:cell-row cell) - (cl-tiled:cell-column cell)) - (tile-character - (cl-tiled:cell-tile cell)))) - - -(defun screen-matrix-set-map (matrix map-path) - "Draw a Tiled-format tilemap to the 2D array." - (mapcar (lambda (layer) (screen-matrix-set-map-layer matrix layer)) - (cl-tiled:map-layers (cl-tiled:load-map map-path))) - matrix) - - -(defun screen-matrix-set-map-layer (matrix tile-layer) - "Set an array's elements to those corresponding the given Tiled -tile-layer's cells. a Tiled tile-layer to the screen." - (mapcar (lambda (cell) (screen-matrix-set-char-cell matrix cell)) - (cl-tiled:layer-cells tile-layer)) - matrix) - - -(defun tile-character (tile) - "Given a tileset's tile, return it's corresponding text character, -assuming that the tileset is a bitmap font starting with char-code 32 -with 15 characters-per-line." - (code-char - (+ (* (cl-tiled:tile-row tile) 15) - (cl-tiled:tile-column tile) - 32))) - - -;;; ~ Utilities ~ - + +;;; ——————————————————————————————————— +;;; Misc. utils +;;; ——————————————————————————————————— (defun move-cursor (row column &key (stream *standard-output*)) "Moves cursor to desired position. Borrowed from https://github.com/gorozhin/chlorophyll/ diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index 4e5cc21..c398e51 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -22,12 +22,13 @@ (load "input.lisp") (load "display.lisp") (load "ui.lisp") +(load "overworld.lisp") (defpackage :flora-search-aurora (:export #:main) (:use :cl :flora-search-aurora.input :flora-search-aurora.display - :flora-search-aurora.ui)) + :flora-search-aurora.overworld :flora-search-aurora.ui)) (in-package :flora-search-aurora) @@ -67,21 +68,18 @@ (menu-loop matrix options-menu)))) +(defun make-main-overworld-loop () + (lambda (matrix) + (overworld-loop matrix "/home/jaidyn/.local/src/games/flora search aurora/res/map.tmx"))) + + (defun main () "A pathetic fascimile of a main loop. Look, I'm still tinkering!" (cl-charms:with-curses () (cl-charms:enable-raw-input :interpret-control-characters 't) (clear-screen) - (state-loop (list (make-main-menu-loop))))) + (state-loop (list (make-main-menu-loop) + (make-main-overworld-loop))))) -;; (print-screen-matrix -; (render-menu-strip matrix items 2 5 -;; :max-item-width 20 :height 3))) -;; (screen-matrix-set-map -;; matrix -;; (print-screen-matrix matrix) -;; (loop (print (normalize-char-plist (read-char-plist)))) -;; (sleep 5))) - (main) diff --git a/overworld.lisp b/overworld.lisp new file mode 100644 index 0000000..7d52e69 --- /dev/null +++ b/overworld.lisp @@ -0,0 +1,93 @@ +;;;; 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 +;;;; published by the Free Software Foundation, either version 3 of +;;;; the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program. If not, see . + +;;;; FLORA-SEARCH-AURORA.OVERWORLD +;;;; All game-functions and data relating to the “overworld” (that is, +;;;; the primary gameplay, the RPG-ish-ish bits). + +(defpackage :flora-search-aurora.overworld + (:use :cl + :flora-search-aurora.input :flora-search-aurora.display + :flora-search-aurora.ui) + (:export #:overworld-loop)) + +(in-package :flora-search-aurora.overworld) + + + +;;; ——————————————————————————————————— +;;; Overworld loop +;;; ——————————————————————————————————— +(defun overworld-loop (matrix map) + "The state loop to be used for displaying/processing/input-managing +with menus." + (let ((map (if (or (stringp map) (pathnamep map)) + (cl-tiled:load-map map) + map))) + (sleep .02) + (overworld-loop-draw matrix map) + (overworld-loop-update map))) + + +(defun overworld-loop-draw (matrix map) + "Drawing for." + (matrix-write-tiled-map matrix map)) + + + +(defun overworld-loop-update (map) + "The update loop for menus. It processes all input, state, etc, and +returns the new state of the menu." + 't) + + + + +;;; ——————————————————————————————————— +;;; Mapping & map-rendering +;;; ——————————————————————————————————— +(defun matrix-write-tiled-cell (matrix cell) + "Set a matrice's (2d array's) element corresponding to +a Tiled cell's character-value, using it's column and row." + (setf (aref matrix + (cl-tiled:cell-row cell) + (cl-tiled:cell-column cell)) + (tiled-tile-character + (cl-tiled:cell-tile cell)))) + + +(defun matrix-write-tiled-map (matrix map) + "Draw a Tiled-format tilemap to the 2D array." + (mapcar (lambda (layer) (matrix-write-tiled-map-layer matrix layer)) + (cl-tiled:map-layers map)) + matrix) + + +(defun matrix-write-tiled-map-layer (matrix tile-layer) + "Set an array's elements to those corresponding the given Tiled +tile-layer's cells. a Tiled tile-layer to the screen." + (mapcar (lambda (cell) (matrix-write-tiled-cell matrix cell)) + (cl-tiled:layer-cells tile-layer)) + matrix) + + +(defun tiled-tile-character (tile) + "Given a tileset's tile, return it's corresponding text character, +assuming that the tileset is a bitmap font starting with char-code 32 +with 15 characters-per-line." + (code-char + (+ (* (cl-tiled:tile-row tile) 15) + (cl-tiled:tile-column tile) + 32)))