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/game.scm | |
parent | 58266627bf3ea66dfc6f8434c32304758d1d9e98 (diff) |
Allow player to shoot and add flowers to harvest pollen from.
Diffstat (limited to 'bonnie-bee/game.scm')
-rw-r--r-- | bonnie-bee/game.scm | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/bonnie-bee/game.scm b/bonnie-bee/game.scm index 5290ab8..ad1d9c3 100644 --- a/bonnie-bee/game.scm +++ b/bonnie-bee/game.scm @@ -3,6 +3,7 @@ #:use-module (bonnie-bee assets) #:use-module (bonnie-bee bullet) #:use-module (bonnie-bee common) + #:use-module (bonnie-bee flower) #:use-module (bonnie-bee player) #:use-module (chickadee data quadtree) #:use-module (chickadee graphics color) @@ -21,34 +22,36 @@ (define-class <game> (<scene-2d>) (quadtree #:getter quadtree #:init-form (make-quadtree %game-bounds))) +(define-method (spawn (game <game>) (actor <actor>)) + (set! (quadtree actor) (quadtree game)) + (attach-to game actor)) + +(define-method (player (game <game>)) + (& game player)) + +(define-method (bullets (game <game>)) + (& game bullets)) + (define-method (on-boot (game <game>)) + (set! *random-state* (random-state-from-platform)) (set-cameras! game) (attach-to game (make <bullets> #:name 'bullets - #:quadtree (quadtree game))) - (let loop ((i 0)) - (when (< i 100) - (add-bullet (& game bullets) pollen-pickup - (vec2 (* (random:uniform) 320.0) - (* (random:uniform) 240.0)) - (vec2 (random:uniform) - (random:uniform))) - (loop (+ i 1))))) - -(define-method (spawn (game <game>) (actor <actor>)) - (set! (quadtree actor) (quadtree game)) - (attach-to game actor)) + #:quadtree (quadtree game)))) (define-method (on-enter (game <game>)) (spawn game (make <player> #:name 'player #:position (vec2 (/ %game-width 2.0) 20.0) - #:hitbox (make-rect -2.0 -2.0 4.0 4.0)))) - -(define-method (player (game <game>)) - (& game player)) + #:hitbox (make-rect -2.0 -2.0 4.0 4.0))) + (spawn game + (make <flower> + #:position (vec2 (/ %game-width 2.0) + (/ %game-height 2.0)) + #:hitbox (make-rect -32.0 -32.0 64.0 64.0) + #:health 10))) (define-method (on-key-press (game <game>) key modifiers repeat?) (case key @@ -77,3 +80,16 @@ (set! (move-up? (player game)) #f)) ((z) (set! (shoot? (player game)) #f)))) + +(define-method (update (game <game>) dt) + (next-method) + (shoot-maybe (player game) (bullets game)) + (for-each-child (lambda (child) + (when (and (is-a? child <damageable>) + (dead? child)) + (on-death child (bullets game)) + (quadtree-delete! (quadtree game) + (world-hitbox child) + child) + (detach child))) + game)) |