From 7cbe9c175aad6fe7e5cb93c42393f570804af7a5 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 9 Jul 2022 13:12:50 -0500 Subject: [example] including rotation in collision handling --- examples/09-ghoulspree.lisp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/09-ghoulspree.lisp b/examples/09-ghoulspree.lisp index d0e5ca1..ffeb324 100644 --- a/examples/09-ghoulspree.lisp +++ b/examples/09-ghoulspree.lisp @@ -40,7 +40,7 @@ (with-accessors ((dr dr) (dx dx) (dy dy) (x ww::x) (y ww::y) (r ww::rotation)) thing (incf x dx) (incf y dy) - (incf r dr))) ;; rotation diminishes every round, just aesthetic. + (incf r dr))) (defun clamp (lo val hi) "Returns VAL if (< LO VAL HI), otherwise returns LO or HI depending @@ -58,14 +58,17 @@ on which boundary VAL is outside of." (loop for ,b in ,more-a do (progn ,@body)) ))) (defun handle-collision (g1 g2 &optional (friction 0.99)) - (with-slots ((dx1 dx) (dy1 dy)) g1 - (with-slots ((dx2 dx) (dy2 dy)) g2 + (with-slots ((dx1 dx) (dy1 dy) (dr1 dr)) g1 + (with-slots ((dx2 dx) (dy2 dy) (dr2 dr)) g2 (let ((tdx (* friction dx1)) - (tdy (* friction dy1))) + (tdy (* friction dy1)) + (tdr (* friction dr1))) (setf dx1 (* friction dx2) dy1 (* friction dy2) + dr1 (* friction dr2) dx2 tdx - dy2 tdy))))) + dy2 tdy + dr2 tdr))))) (ww:defhandler moveghouls (ww:on-perframe (app) @@ -74,7 +77,7 @@ on which boundary VAL is outside of." (with-pairs (g1 g2) (ww:container-units app) (when (ww:units-intersect-p g1 g2) - (handle-collision g1 g2 0.99) + (handle-collision g1 g2 1.0) ;; need a "bounce" (advance-pos g1) (advance-pos g1) -- cgit v1.2.3