summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.scm49
1 files changed, 29 insertions, 20 deletions
diff --git a/game.scm b/game.scm
index c015b10..839796e 100644
--- a/game.scm
+++ b/game.scm
@@ -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))))))))
;;;