From 31619ba2715d0b78b7b536f6412acd402d7096c8 Mon Sep 17 00:00:00 2001 From: Boutade Date: Wed, 16 Oct 2019 13:56:47 -0500 Subject: basic emoting --- assets.lisp | 57 ++++++++++++++++++++++++++++++++++---- assets/emoji.png | Bin 0 -> 37938 bytes the-price-of-a-cup-of-coffee.lisp | 50 ++++++++++++++++++++++++--------- 3 files changed, 89 insertions(+), 18 deletions(-) create mode 100644 assets/emoji.png diff --git a/assets.lisp b/assets.lisp index 823d99b..0df33a6 100644 --- a/assets.lisp +++ b/assets.lisp @@ -45,27 +45,64 @@ (:NAME "WalkRight1" :X 64 :Y 0 :WIDTH 64 :HEIGHT 128) (:NAME "WalkRight2" :X 0 :Y 0 :WIDTH 64 :HEIGHT 128))) +(defparameter +emoji-defs+ +'((:NAME "angry" :X 216 :Y 144 + :WIDTH 72 :HEIGHT 72) + (:NAME "asshole" :X 216 :Y 216 + :WIDTH 72 :HEIGHT 72) + (:NAME "breakdown" :X 288 :Y 0 + :WIDTH 72 :HEIGHT 72) + (:NAME "chance" :X 72 :Y 216 + :WIDTH 72 :HEIGHT 72) + (:NAME "death" :X 144 :Y 216 + :WIDTH 72 :HEIGHT 72) + (:NAME "dollars" :X 0 :Y 288 + :WIDTH 72 :HEIGHT 72) + (:NAME "food1" :X 144 :Y 72 + :WIDTH 72 :HEIGHT 72) + (:NAME "food2" :X 144 :Y 144 + :WIDTH 72 :HEIGHT 72) + (:NAME "food3" :X 216 :Y 0 + :WIDTH 72 :HEIGHT 72) + (:NAME "food4" :X 72 :Y 144 + :WIDTH 72 :HEIGHT 72) + (:NAME "food5" :X 0 :Y 216 + :WIDTH 72 :HEIGHT 72) + (:NAME "incapacitated" :X 72 :Y 72 + :WIDTH 72 :HEIGHT 72) + (:NAME "nauseated" :X 144 :Y 0 + :WIDTH 72 :HEIGHT 72) + (:NAME "relaxed" :X 0 :Y 144 + :WIDTH 72 :HEIGHT 72) + (:NAME "sick" :X 72 :Y 0 + :WIDTH 72 :HEIGHT 72) + (:NAME "stressed" :X 0 :Y 72 + :WIDTH 72 :HEIGHT 72) + (:NAME "very-angry" :X 0 :Y 0 + :WIDTH 72 :HEIGHT 72))) + (defparameter +shared-faces+ (create-sprite-faces +tile-defs+)) + + (defparameter +nance-sheet-image+ "assets/Nance.png") (defparameter +suit-sheet-image+ "assets/Suit.png") (defparameter +nomry-sheet-image+ "assets/Normy.png") (defparameter +things-look-up-track-path+ #P"assets/thingslookup.mp3") (defparameter +cold-day-track-path+ #P"assets/coldday.mp3") - +(defparameter +emoji-sheet-image+ #P"assets/emoji.png") (defvar *nance-texture*) (defvar *suit-texture*) (defvar *normy-texture*) +(defvar *expression-texture*) (defvar *harmony-initialized-p* nil) (defvar *cold-day-track*) (defvar *looking-up-track*) (defvar *current-track*) - - (defun boot-up-assets (renderer) (with-surface-from-file (surf +nance-sheet-image+) (setf *nance-texture* (sdl2:create-texture-from-surface renderer surf))) @@ -76,6 +113,9 @@ (with-surface-from-file (surf +nomry-sheet-image+) (setf *normy-texture* (sdl2:create-texture-from-surface renderer surf))) + (with-surface-from-file (surf +emoji-sheet-image+) + (setf *expression-texture* (sdl2:create-texture-from-surface renderer surf))) + (unless *harmony-initialized-p* (harmony-simple:initialize) (setf *looking-up-track* (harmony-simple:play +things-look-up-track-path+ :music :loop t)) @@ -85,13 +125,20 @@ (harmony-simple:stop *cold-day-track*) (setf *harmony-initialized-p* t))) - (defun free-assets () (harmony-simple:stop *current-track*) + (sdl2:destroy-texture *expression-texture*) (sdl2:destroy-texture *nance-texture*) (sdl2:destroy-texture *normy-texture*) (sdl2:destroy-texture *suit-texture*)) +(defvar *expression-cache* (make-hash-table :test 'equal)) - +(defun get-expression (expression) + "Returns a rect used as the render source in a call to RENDER-COPY" + (let ((exp (gethash expression *expression-cache*))) + (unless exp + (setf exp (find-tile-rect +emoji-defs+ expression)) + (setf (gethash expression *expression-cache*) exp)) + exp)) diff --git a/assets/emoji.png b/assets/emoji.png new file mode 100644 index 0000000..949e01b Binary files /dev/null and b/assets/emoji.png differ diff --git a/the-price-of-a-cup-of-coffee.lisp b/the-price-of-a-cup-of-coffee.lisp index f9652b8..e1a37ed 100644 --- a/the-price-of-a-cup-of-coffee.lisp +++ b/the-price-of-a-cup-of-coffee.lisp @@ -15,6 +15,11 @@ (defvar *tweens* nil) +(defvar *expression-rect* + (sdl2:make-rect 0 0 32 32) + "used to render expressions.") + + (defstruct keys-down left right up down action) (defvar *keys-down* (make-keys-down)) @@ -105,10 +110,12 @@ (setf (walk-speed *nance*) (round (* 2 (walk-speed *nance*)))))) + (def-normal-class human () (walk-vec (cons 0 0)) (walk-speed 6) diag-walk-speed + expression ;; nil or a string pos sheet (faces ((lambda () +shared-faces+))) @@ -160,12 +167,30 @@ (setf frame (mod (1+ frame) (length (funcall face faces))))))) +(defun set-expression-rect (human) + (setf (sdl2:rect-x *expression-rect*) + (sdl2:rect-x (pos human))) + (setf (sdl2:rect-y *expression-rect*) + (- (sdl2:rect-y (pos human)) + 36))) + (defmethod render ((human human) renderer) - (with-slots (pos sheet faces face frame) human + (with-slots (pos sheet faces face frame expression) human (sdl2:render-copy renderer sheet :dest-rect pos - :source-rect (get-frame-rect human)))) - + :source-rect (get-frame-rect human)) + (when expression + (set-expression-rect human) + (sdl2:render-copy renderer *expression-texture* + :dest-rect *expression-rect* + :source-rect (get-expression expression))))) + +(defun emote (who emotion &optional duration) + (setf (expression who) emotion) + (when duration + (let ((pause (pause duration (sdl2:get-ticks)))) + (setf (on-complete pause) (lambda () (setf (expression who) nil))) + (push pause *tweens*)))) (def-normal-class hero (human) (sick-p nil)) @@ -405,10 +430,12 @@ (rem-walk-hero-down))))) (defun update-tweens (time) - (when *coffee-break-tween* - (run-tween *coffee-break-tween* time) - (when (tween-finished-p *coffee-break-tween* time) - (setf *coffee-break-tween* nil)))) + (dolist (tween *tweens*) + (run-tween tween time)) + (setf *tweens* + (delete-if ($ #'tween-finished-p _ time) + *tweens*))) + (defun dist (person1 person2) (let ((dx (- (x-pos person1) (x-pos person2))) @@ -470,12 +497,9 @@ (sdl2:set-render-draw-color renderer 80 80 80 255) (sdl2:render-clear renderer) - (setf *to-render-by-y* (sort *to-render-by-y* #'< :key #'y-pos)) - - ;; render characters - ;;(render *nance* renderer) - - ;; render pedestrians + ;; render characters and other objects + (setf *to-render-by-y* + (sort *to-render-by-y* #'< :key #'y-pos)) (dolist (person *to-render-by-y*) (render person renderer)) -- cgit v1.2.3