summaryrefslogtreecommitdiff
path: root/bonnie-bee/player.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2021-10-20 18:42:10 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2021-10-20 18:42:10 -0400
commitae60497f7722e01ccceebe799b5820717e048eb3 (patch)
tree7977b53565d5f1e259d90903213f1add3fefabce /bonnie-bee/player.scm
parentde833c9d524d2e47b3812612995290795d2e7b84 (diff)
Haven't committed in days, oops!
Diffstat (limited to 'bonnie-bee/player.scm')
-rw-r--r--bonnie-bee/player.scm114
1 files changed, 103 insertions, 11 deletions
diff --git a/bonnie-bee/player.scm b/bonnie-bee/player.scm
index 9a5da1c..6f6cd91 100644
--- a/bonnie-bee/player.scm
+++ b/bonnie-bee/player.scm
@@ -2,12 +2,19 @@
#:use-module (bonnie-bee actor)
#:use-module (bonnie-bee assets)
#:use-module (bonnie-bee bullet)
+ #:use-module (bonnie-bee common)
+ #:use-module (bonnie-bee flower)
+ #:use-module (chickadee audio)
+ #:use-module (chickadee game-loop)
+ #:use-module (chickadee math)
#:use-module (chickadee math vector)
#:use-module (chickadee scripting)
#:use-module (oop goops)
+ #:use-module (starling asset)
#:use-module (starling node)
#:use-module (starling node-2d)
- #:export (<player>
+ #:export (%max-pollen
+ <player>
move-left?
move-right?
move-down?
@@ -16,7 +23,12 @@
speed
lives
pollen
- shoot-maybe))
+ score
+ shoot-maybe
+ bomb
+ add-to-score))
+
+(define %max-pollen 50)
(define-class <player> (<actor>)
(move-left? #:accessor move-left? #:init-value #f)
@@ -25,10 +37,13 @@
(move-up? #:accessor move-up? #:init-value #f)
(shoot? #:accessor shoot? #:init-value #f #:watch? #t)
(last-shot #:accessor last-shot #:init-value 0)
- (shot-interval #:getter shot-interval #:init-value 2)
- (speed #:accessor speed #:init-value 2.0)
+ (shot-interval #:getter shot-interval #:init-value (steps 2))
+ (speed #:accessor speed #:init-value 2.5)
(lives #:accessor lives #:init-value 3)
- (pollen #:accessor pollen #:init-value 0))
+ (invincible? #:accessor invincible? #:init-value #f)
+ (pollen #:accessor pollen #:init-value 0)
+ (score #:accessor score #:init-value 0)
+ (bombing? #:accessor bombing? #:init-value #f))
(define-method (on-boot (player <player>))
(attach-to player
@@ -43,6 +58,19 @@
(when (and new (not (and old new)))
(set! (last-shot player) 0)))))
+(define-method (after-move (player <player>))
+ (let ((p (position player)))
+ (cond
+ ((< (vec2-x p) 8.0)
+ (set-vec2-x! p 8.0))
+ ((> (vec2-x p) 312.0)
+ (set-vec2-x! p 312.0)))
+ (cond
+ ((< (vec2-y p) 8.0)
+ (set-vec2-y! p 8.0))
+ ((> (vec2-y p) 232.0)
+ (set-vec2-y! p 232.0)))))
+
(define-method (update (player <player>) dt)
(let ((v (velocity player)))
(set-vec2! v
@@ -54,13 +82,42 @@
(vec2-mult! v (speed player)))
(next-method))
+(define-method (lose-life (player <player>))
+ (unless (invincible? player)
+ (set! (lives player) (max (- (lives player) 1) 0))
+ (set! (invincible? player) #t)
+ (audio-play (asset-ref player-death-sound))
+ (run-script player
+ (blink player 20 (steps 5))
+ (set! (invincible? player) #f))))
+
(define-method (on-collide (player <player>) (bullet <bullet>))
- (if (eq? (type bullet) pollen-pickup)
- (begin
- (kill-bullet bullet)
- (set! (pollen player) (+ (pollen player) 1))
- #t)
- #f))
+ (cond
+ ((eq? (type bullet) pollen-pickup)
+ (audio-play (asset-ref pickup-sound) #:volume 0.3)
+ (kill-bullet bullet)
+ (add-to-score player 1)
+ (set! (pollen player) (min (+ (pollen player) 1) %max-pollen))
+ #t)
+ ((or (eq? (type bullet) small-enemy-bullet)
+ (eq? (type bullet) medium-enemy-bullet)
+ (eq? (type bullet) large-enemy-bullet))
+ (kill-bullet bullet)
+ (lose-life player)
+ #t)
+ (else #f)))
+
+(define-method (on-collide (player <player>) (thing <damageable>))
+ (lose-life player))
+
+(define-method (on-collide (thing <damageable>) (player <player>))
+ (lose-life player))
+
+(define-method (on-collide (player <player>) (flower <flower>))
+ #f)
+
+(define-method (on-collide (flower <flower>) (player <player>))
+ #f)
(define-method (shoot-maybe (player <player>) bullets)
(with-agenda (agenda player)
@@ -69,7 +126,42 @@
(shot-interval player)))
(let ((p (position player)))
(set! (last-shot player) (agenda-time))
+ (audio-play (asset-ref player-shoot-sound) #:volume 0.2)
(add-bullet bullets
player-primary-bullet
(vec2 (vec2-x p) (+ (vec2-y p) 14.0))
(vec2 0.0 6.0))))))
+
+(define-method (bomb (player <player>))
+ (unless (or (bombing? player) (< (pollen player) 10))
+ (run-script player
+ (let* ((times (floor (/ (pollen player) 10)))
+ (num-bullets 64)
+ (theta-step (/ tau num-bullets))
+ (radius 16.0)
+ (speed 5.0)
+ (p (position player))
+ (bullets (bullets (parent player))))
+ (set! (bombing? player) #t)
+ (set! (pollen player) 0)
+ (set! (invincible? player) #t)
+ (let loop ((i 0))
+ (when (< i times)
+ (audio-play (asset-ref player-bomb-sound))
+ (let shot-loop ((j 0))
+ (when (< j num-bullets)
+ (let ((theta (* j theta-step)))
+ (add-bullet bullets
+ player-bomb-bullet
+ (vec2/polar p radius theta)
+ (vec2 (* (cos theta) speed)
+ (* (sin theta) speed))))
+ (shot-loop (+ j 1))))
+ (sleep (* (current-timestep) 3))
+ (loop (+ i 1))))
+ (sleep 1.0)
+ (set! (invincible? player) #f)
+ (set! (bombing? player) #f)))))
+
+(define-method (add-to-score (player <player>) points)
+ (set! (score player) (+ (score player) points)))