diff options
author | Boutade <thegoofist@protonmail.com> | 2019-10-19 07:59:50 -0500 |
---|---|---|
committer | Boutade <thegoofist@protonmail.com> | 2019-10-19 07:59:50 -0500 |
commit | 3ab898bcd0cca6d08fab5d30defda9b69bac8029 (patch) | |
tree | 5b1ba133e22dc14aa5e9435e2197ea094f0f506b | |
parent | b07a726868d66306fcb392dfb4f5cfb43e2b235c (diff) |
collision detection
-rw-r--r-- | the-price-of-a-cup-of-coffee.lisp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/the-price-of-a-cup-of-coffee.lisp b/the-price-of-a-cup-of-coffee.lisp index f506ada..63bd4cc 100644 --- a/the-price-of-a-cup-of-coffee.lisp +++ b/the-price-of-a-cup-of-coffee.lisp @@ -285,7 +285,8 @@ (with-slots (pos) hero (setf (sdl2:rect-x pos) (mod (sdl2:rect-x pos) +window-width+)) - (if (in-front-of-door-p) + (snap-hit-box-to hero *nance-hit-box*) + (if (in-front-of-door-p) (when (not *door-open-p*) (open-door)) (when *door-open-p* @@ -647,6 +648,26 @@ ;; update the displayd animation (set-walk-face-by-walk-vec person1))) + +(defun reset-pedestrian (ped) + (setf (already-asked ped) nil) + (setf (sdl2:rect-y (pos ped)) (random-y-pos)) + (setf (sdl2:rect-x (pos ped)) -49)) + +(defvar *ped-hit-box* (sdl2:make-rect 0 0 64 40)) +(defvar *nance-hit-box* (sdl2:make-rect 0 0 64 40)) + +(defun snap-hit-box-to (human hitbox) + (setf (sdl2:rect-x hitbox) (x-pos human)) + (setf (sdl2:rect-y hitbox) (+ (y-pos human) 88))) + +(defun collision-check (ped) + (when *collision-on-p* + (snap-hit-box-to ped *ped-hit-box*) + (when (sdl2:has-intersect *ped-hit-box* *nance-hit-box*) + (print "collision detected!")))) + + (defmethod update ((ped pedestrian) time) (call-next-method) (with-slots (pos react-per-sec next-react) ped @@ -658,12 +679,11 @@ (/ 1000 react-per-sec))))) (adjust-walk-relative-to ped *nance*)) + (collision-check ped) + (when (or (< (sdl2:rect-x pos) -50) (< +window-width+ (sdl2:rect-x pos))) - (setf (already-asked ped) nil) - (setf (sdl2:rect-y pos) (random-y-pos)) - (setf (sdl2:rect-x pos) -49)))) - + (reset-pedestrian ped)))) (defmethod update ((game (eql :game)) time) (update *nance* time) |