aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-07-09 13:12:50 -0500
committerColin Okay <okay@toyful.space>2022-07-09 13:12:50 -0500
commit7cbe9c175aad6fe7e5cb93c42393f570804af7a5 (patch)
tree3675c4661d13de40ebc3ab892617526d91602d6e
parent33534367e22ea1b9eb44ea5b0fc648b7988ae528 (diff)
[example] including rotation in collision handling
-rw-r--r--examples/09-ghoulspree.lisp15
1 files changed, 9 insertions, 6 deletions
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)