diff options
author | David Thompson <dthompson2@worcester.edu> | 2016-05-03 22:07:42 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2016-05-03 22:07:42 -0400 |
commit | a0c2bcc7cde0e4c1fb50a361f320774edea6b688 (patch) | |
tree | 03649200759387a13dc830c3468eb55a5104221a | |
parent | bef945517b78b2354960ade9ea1095e7770cfab6 (diff) |
Add a bigger hitbox for absorbing bullets.
-rw-r--r-- | game.scm | 49 |
1 files changed, 29 insertions, 20 deletions
@@ -66,6 +66,7 @@ (direction player-direction (vector2 0 0)) (shooting? player-shooting? #f) (hitbox player-hitbox (make-rect -1 1 2 4)) + (absorb-hitbox player-absorb-hitbox (make-rect -9 -2 16 6)) (last-death-time player-last-death-time #f)) (define-record-type* <enemy> @@ -287,6 +288,9 @@ (define (player-world-hitbox player) (rect-move (player-hitbox player) (player-position player))) +(define (player-world-absorb-hitbox player) + (rect-move (player-absorb-hitbox player) (player-position player))) + (define (enemy-world-hitbox enemy) (rect-move (enemy-hitbox enemy) (enemy-position enemy))) @@ -301,8 +305,13 @@ (rect-intersects? (enemy-world-hitbox enemy) (bullet-world-hitbox bullet))) +(define (player/bullet-polarity-eq? player bullet) + (eq? (player-polarity player) (bullet-polarity bullet))) + (define (player/bullet-collision? player bullet) - (rect-intersects? (player-world-hitbox player) + (rect-intersects? (if (player/bullet-polarity-eq? player bullet) + (player-world-absorb-hitbox player) + (player-world-hitbox player)) (bullet-world-hitbox bullet))) (define (collide-enemies-and-bullets enemies player-bullets stats time) @@ -387,25 +396,25 @@ (() (values player (reverse new-bullets) stats '())) ((bullet . rest) - (if (player/bullet-collision? (actor-ref player) (actor-ref bullet)) - (let* ((invincible? (player-invincible? (actor-ref player) time)) - (matched-polarity? (eq? (player-polarity (actor-ref player)) - (bullet-polarity (actor-ref bullet)))) - (hit? (not (or invincible? matched-polarity?))) - (new-player (if hit? - (call-with-actor player - (lambda (player) - (kill-player player time))) - player)) - (position (player-position (actor-ref player))) - (explosion (make-explosion #:type 'player - #:position position - #:time time))) - (values new-player - (append (reverse new-bullets) rest) - (if hit? (decrement-life stats) stats) - (if hit? (list explosion) '()))) - (loop rest (cons bullet new-bullets))))))) + (let* ((b (actor-ref bullet)) + (p (actor-ref player))) + (if (player/bullet-collision? p b) + (let* ((hit? (not (or (player-invincible? p time) + (player/bullet-polarity-eq? p b)))) + (new-player (if hit? + (call-with-actor player + (lambda (player) + (kill-player player time))) + player)) + (position (player-position p)) + (explosion (make-explosion #:type 'player + #:position position + #:time time))) + (values new-player + (append (reverse new-bullets) rest) + (if hit? (decrement-life stats) stats) + (if hit? (list explosion) '()))) + (loop rest (cons bullet new-bullets)))))))) ;;; |