diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2021-10-16 16:22:08 -0400 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2021-10-16 16:22:08 -0400 |
commit | de833c9d524d2e47b3812612995290795d2e7b84 (patch) | |
tree | 707246a8c3324b6b9d16507241a1e00ce2843168 /bonnie-bee/player.scm | |
parent | 58266627bf3ea66dfc6f8434c32304758d1d9e98 (diff) |
Allow player to shoot and add flowers to harvest pollen from.
Diffstat (limited to 'bonnie-bee/player.scm')
-rw-r--r-- | bonnie-bee/player.scm | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/bonnie-bee/player.scm b/bonnie-bee/player.scm index 6e8f7fb..9a5da1c 100644 --- a/bonnie-bee/player.scm +++ b/bonnie-bee/player.scm @@ -1,7 +1,9 @@ (define-module (bonnie-bee player) #:use-module (bonnie-bee actor) #:use-module (bonnie-bee assets) + #:use-module (bonnie-bee bullet) #:use-module (chickadee math vector) + #:use-module (chickadee scripting) #:use-module (oop goops) #:use-module (starling node) #:use-module (starling node-2d) @@ -13,14 +15,17 @@ shoot? speed lives - pollen)) + pollen + shoot-maybe)) (define-class <player> (<actor>) (move-left? #:accessor move-left? #:init-value #f) (move-right? #:accessor move-right? #:init-value #f) (move-down? #:accessor move-down? #:init-value #f) (move-up? #:accessor move-up? #:init-value #f) - (shoot? #:accessor shoot? #: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) (lives #:accessor lives #:init-value 3) (pollen #:accessor pollen #:init-value 0)) @@ -32,6 +37,12 @@ #:index 12 #:origin (vec2 16.0 16.0)))) +(define-method (on-change (player <player>) slot-name old new) + (case slot-name + ((shoot?) + (when (and new (not (and old new))) + (set! (last-shot player) 0))))) + (define-method (update (player <player>) dt) (let ((v (velocity player))) (set-vec2! v @@ -42,3 +53,23 @@ (vec2-normalize! v) (vec2-mult! v (speed player))) (next-method)) + +(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)) + +(define-method (shoot-maybe (player <player>) bullets) + (with-agenda (agenda player) + (when (and (shoot? player) + (>= (- (agenda-time) (last-shot player)) + (shot-interval player))) + (let ((p (position player))) + (set! (last-shot player) (agenda-time)) + (add-bullet bullets + player-primary-bullet + (vec2 (vec2-x p) (+ (vec2-y p) 14.0)) + (vec2 0.0 6.0)))))) |