Better drawing of strange-width NPC/player faces

Now entities (like the player) will be drawn more
evenly, even if their faces are ~~owo~~ WEIRD uwu
This commit is contained in:
Jaidyn Ann 2023-06-14 16:36:34 -05:00
parent f492aa6dba
commit 939a433f32

View File

@ -33,7 +33,7 @@
(defun overworld-state (defun overworld-state
(matrix &key (map-path nil) (map (load-map-chunks map-path)) (matrix &key (map-path nil) (map (load-map-chunks map-path))
(entities-alist (entities-alist
'((player :coords (:x 1 :y 1) :face "uwu" :direction right)))) '((player :coords (:x 3 :y 3) :face "uwu" :direction right))))
"Render the given map to the matrix and take user-input for one frame. "Render the given map to the matrix and take user-input for one frame.
A state-function for use with STATE-LOOP." A state-function for use with STATE-LOOP."
(sleep .02) (sleep .02)
@ -175,30 +175,38 @@ with 15 characters-per-line."
(defun matrix-write-entity (matrix entity-plist) (defun matrix-write-entity (matrix entity-plist)
"Render an entity-plist to the matrix." "Render an entity-plist to the matrix."
(matrix-write-entity-head matrix entity-plist)
(matrix-write-entity-legs matrix entity-plist))
(defun matrix-write-entity-head (matrix entity-plist)
"Draw an entitys head. There aren't any Mami Tomoes in this game, dang it!"
(let* ((screen-coords (world-coords->screen-coords (getf entity-plist :coords))) (let* ((screen-coords (world-coords->screen-coords (getf entity-plist :coords)))
(x (getf screen-coords :x)) (direction (getf entity-plist :direction))
(y (getf screen-coords :y)) (face (getf entity-plist :face))
(face (getf entity-plist :face))) (width (+ (length face) 2)) ;; Face + |borders|
(ignore-errors (setf (aref matrix y x) #\|)) (y (- (getf screen-coords :y) 1))
(ignore-errors (setf (aref matrix y (+ (length face) x 1)) (x (if (eq direction 'right)
#\|)) (- (getf screen-coords :x) (floor (/ width 2)) 0)
(- (getf screen-coords :x) (floor (/ width 2)) 0))))
(render-line matrix face (+ x 1) y) (render-line matrix face (+ x 1) y)
(matrix-write-entity-legs matrix entity-plist))) (ignore-errors (setf (aref matrix y x) #\|))
(ignore-errors (setf (aref matrix y (+ width x -1))
#\|))))
(defun matrix-write-entity-legs (matrix entity-plist) (defun matrix-write-entity-legs (matrix entity-plist)
"Draw an entity's legs — a surprisingly in-depth task!" "Draw a bipdel entitys legs — a surprisingly in-depth task!"
(let* ((screen-coords (world-coords->screen-coords (getf entity-plist :coords))) (let* ((screen-coords (world-coords->screen-coords (getf entity-plist :coords)))
(x (getf screen-coords :x)) (x (getf screen-coords :x))
(y (+ (getf screen-coords :y) 1)) (y (getf screen-coords :y))
(width (+ (length (getf entity-plist :face)) 2))
(direction (getf entity-plist :direction))) (direction (getf entity-plist :direction)))
(cond ((eq direction 'right) (cond ((eq direction 'right)
(ignore-errors (setf (aref matrix y (+ x 1)) #\|)) (ignore-errors (setf (aref matrix y x) #\|))
(ignore-errors (setf (aref matrix y (+ x 2)) #\|))) (ignore-errors (setf (aref matrix y (- x 1)) #\|)))
((eq direction 'left) ((eq direction 'left)
(ignore-errors (setf (aref matrix y (+ x width -2)) #\|)) (ignore-errors (setf (aref matrix y x) #\|))
(ignore-errors (setf (aref matrix y (+ x width -3)) #\|)))))) (ignore-errors (setf (aref matrix y (+ x 1)) #\|))))))