From 5b461c68e3194aef85bd175d51a30f205adb327f Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 16 Apr 2020 22:01:22 -0400 Subject: Day 6 progress. --- lisparuga/player.scm | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'lisparuga/player.scm') diff --git a/lisparuga/player.scm b/lisparuga/player.scm index 6a85cc4..ae126e2 100644 --- a/lisparuga/player.scm +++ b/lisparuga/player.scm @@ -47,6 +47,7 @@ speed invincible? shooting? + bounds-check? steer start-shooting stop-shooting @@ -77,9 +78,11 @@ (speed #:accessor speed #:init-value 2.5) (invincible? #:accessor invincible? #:init-value #f) (shooting? #:accessor shooting? #:init-value #f) - (shoot-time #:accessor shoot-time #:init-value 0)) + (shoot-time #:accessor shoot-time #:init-value 0) + (bounds-check? #:accessor bounds-check? #:init-value #t)) (define-method (reset (player )) + (show player) (set! (polarity player) 'white) (set-vec2! (velocity player) 0.0 0.0) (set! (score player) 0) @@ -91,6 +94,7 @@ (set! (invincible? player) #f) (set! (shooting? player) #f) (set! (shoot-time player) 0) + (set! (bounds-check? player) #t) (refresh-sprite player)) (define-method (dead? (player )) @@ -124,18 +128,19 @@ (define-method (update (player ) dt) ;; Adjust velocity to force player to stay within the bounds of the ;; screen. - (let ((p (position player)) - (v (velocity player))) - (cond - ((< (+ (vec2-x p) (vec2-x v)) 0.0) - (set-vec2-x! v (- (vec2-x p)))) - ((> (+ (vec2-x p) (vec2-x v)) 160.0) - (set-vec2-x! v (- 160.0 (vec2-x p))))) - (cond - ((< (+ (vec2-y p) (vec2-y v)) 0.0) - (set-vec2-y! v (- (vec2-y p)))) - ((> (+ (vec2-y p) (vec2-y v)) 240.0) - (set-vec2-y! v (- 240.0 (vec2-y p)))))) + (when (bounds-check? player) + (let ((p (position player)) + (v (velocity player))) + (cond + ((< (+ (vec2-x p) (vec2-x v)) 0.0) + (set-vec2-x! v (- (vec2-x p)))) + ((> (+ (vec2-x p) (vec2-x v)) 160.0) + (set-vec2-x! v (- 160.0 (vec2-x p))))) + (cond + ((< (+ (vec2-y p) (vec2-y v)) 0.0) + (set-vec2-y! v (- (vec2-y p)))) + ((> (+ (vec2-y p) (vec2-y v)) 240.0) + (set-vec2-y! v (- 240.0 (vec2-y p))))))) ;; Shooting logic (when (shooting? player) (let ((t (shoot-time player))) -- cgit v1.2.3