summaryrefslogtreecommitdiff
path: root/lisparuga/player.scm
diff options
context:
space:
mode:
Diffstat (limited to 'lisparuga/player.scm')
-rw-r--r--lisparuga/player.scm31
1 files changed, 18 insertions, 13 deletions
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 <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 <player>))
@@ -124,18 +128,19 @@
(define-method (update (player <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)))