summaryrefslogtreecommitdiff
path: root/bonnie-bee/game.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2021-10-15 23:29:49 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2021-10-15 23:29:49 -0400
commit58266627bf3ea66dfc6f8434c32304758d1d9e98 (patch)
tree2f398d7cc9230250f5d11abece2e9e8ae0f05dd8 /bonnie-bee/game.scm
parenta2b03f564d1eb66298c5502b07e36c67f856857e (diff)
Day 1 check-in.
Diffstat (limited to 'bonnie-bee/game.scm')
-rw-r--r--bonnie-bee/game.scm79
1 files changed, 79 insertions, 0 deletions
diff --git a/bonnie-bee/game.scm b/bonnie-bee/game.scm
new file mode 100644
index 0000000..5290ab8
--- /dev/null
+++ b/bonnie-bee/game.scm
@@ -0,0 +1,79 @@
+(define-module (bonnie-bee game)
+ #:use-module (bonnie-bee actor)
+ #:use-module (bonnie-bee assets)
+ #:use-module (bonnie-bee bullet)
+ #:use-module (bonnie-bee common)
+ #:use-module (bonnie-bee player)
+ #:use-module (chickadee data quadtree)
+ #:use-module (chickadee graphics color)
+ #:use-module (chickadee math rect)
+ #:use-module (chickadee math vector)
+ #:use-module (chickadee scripting)
+ #:use-module (oop goops)
+ #:use-module (starling kernel)
+ #:use-module (starling node)
+ #:use-module (starling node-2d)
+ #:use-module (starling scene)
+ #:export (<game>))
+
+(define %game-bounds (make-rect 0.0 0.0 %game-width %game-height))
+
+(define-class <game> (<scene-2d>)
+ (quadtree #:getter quadtree #:init-form (make-quadtree %game-bounds)))
+
+(define-method (on-boot (game <game>))
+ (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))
+
+(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))
+
+(define-method (on-key-press (game <game>) key modifiers repeat?)
+ (case key
+ ((q)
+ (pop-scene (current-kernel)))
+ ((left)
+ (set! (move-left? (player game)) #t))
+ ((right)
+ (set! (move-right? (player game)) #t))
+ ((down)
+ (set! (move-down? (player game)) #t))
+ ((up)
+ (set! (move-up? (player game)) #t))
+ ((z)
+ (set! (shoot? (player game)) #t))))
+
+(define-method (on-key-release (game <game>) key modifiers)
+ (case key
+ ((left)
+ (set! (move-left? (player game)) #f))
+ ((right)
+ (set! (move-right? (player game)) #f))
+ ((down)
+ (set! (move-down? (player game)) #f))
+ ((up)
+ (set! (move-up? (player game)) #f))
+ ((z)
+ (set! (shoot? (player game)) #f))))