From e287a11c4387382277c31735504fc762c33b4cee Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 12 Oct 2022 06:48:14 -0400 Subject: Switch to Catbird engine. --- bonnie-bee/actor.scm | 11 +- bonnie-bee/assets.scm | 63 ++-- bonnie-bee/background.scm | 10 +- bonnie-bee/boss.scm | 24 +- bonnie-bee/bullet.scm | 17 +- bonnie-bee/common.scm | 22 +- bonnie-bee/flower.scm | 14 +- bonnie-bee/game.scm | 791 ++++++++++++++++++++++++++-------------------- bonnie-bee/moth.scm | 10 +- bonnie-bee/player.scm | 31 +- bonnie-bee/pollen.scm | 4 +- bonnie-bee/popcorn.scm | 10 +- bonnie-bee/splash.scm | 105 +++--- bonnie-bee/turret.scm | 12 +- 14 files changed, 637 insertions(+), 487 deletions(-) (limited to 'bonnie-bee') diff --git a/bonnie-bee/actor.scm b/bonnie-bee/actor.scm index 8aec98a..3d693dd 100644 --- a/bonnie-bee/actor.scm +++ b/bonnie-bee/actor.scm @@ -6,9 +6,10 @@ #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (oop goops) - #:use-module (starling asset) - #:use-module (starling node) - #:use-module (starling node-2d) + #:use-module (catbird asset) + #:use-module (catbird node) + #:use-module (catbird node-2d) + #:use-module (catbird scene) #:export ( velocity hitbox @@ -107,7 +108,7 @@ (refresh-world-hitbox actor) (collision-check actor) (add-to-quadtree actor) - (dirty! actor))))) + (expire-local-matrix actor))))) (define-method (dead? (actor )) #f) @@ -138,7 +139,7 @@ (define-method (damage (d ) x) (set! (health d) (max (- (health d) x) 0)) (unless (dead? d) - (audio-play (asset-ref enemy-hit-sound) #:volume 0.25))) + (audio-play (artifact enemy-hit-sound) #:volume 0.25))) (define-method (on-death (d )) #t) diff --git a/bonnie-bee/assets.scm b/bonnie-bee/assets.scm index 3dc35cc..a6c2358 100644 --- a/bonnie-bee/assets.scm +++ b/bonnie-bee/assets.scm @@ -1,8 +1,8 @@ (define-module (bonnie-bee assets) #:use-module (chickadee audio) - #:use-module (chickadee graphics font) + #:use-module (chickadee graphics text) #:use-module (chickadee graphics texture) - #:use-module (starling asset) + #:use-module (catbird asset) #:export (monogram-font background-image particle-image @@ -33,28 +33,37 @@ (let ((prefix (or (getenv "BONNIE_BEE_DATADIR") (getcwd)))) (string-append prefix "/" file-name))) -(define-asset monogram-font (load-font (scope-datadir "assets/fonts/monogram_extended.ttf") 12)) -(define-asset background-image (load-image (scope-datadir "assets/images/background.png"))) -(define-asset particle-image (load-image (scope-datadir "assets/images/particle.png"))) -(define-asset darkness-image (load-image (scope-datadir "assets/images/darkness.png"))) -(define-asset lightness-image (load-image (scope-datadir "assets/images/lightness.png"))) -(define-asset chickadee-image (load-image (scope-datadir "assets/images/chickadee.png"))) -(define-asset bee-atlas (load-tileset (scope-datadir "assets/images/bee.png") 32 32)) -(define-asset bullet-atlas (load-tileset (scope-datadir "assets/images/bullets.png") 16 16)) -(define-asset flower-atlas (load-tileset (scope-datadir "assets/images/flower.png") 64 64)) -(define-asset popcorn-atlas (load-tileset (scope-datadir "assets/images/popcorn.png") 32 32)) -(define-asset turret-atlas (load-tileset (scope-datadir "assets/images/turret.png") 64 64)) -(define-asset moth-atlas (load-tileset (scope-datadir "assets/images/moth.png") 64 64)) -(define-asset beetle-atlas (load-tileset (scope-datadir "assets/images/beetle.png") 128 64)) -(define-asset explosion-sound (load-audio (scope-datadir "assets/sounds/explosion.wav"))) -(define-asset pickup-sound (load-audio (scope-datadir "assets/sounds/pickup.wav"))) -(define-asset enemy-shoot-sound (load-audio (scope-datadir "assets/sounds/enemy-shoot.wav"))) -(define-asset enemy-hit-sound (load-audio (scope-datadir "assets/sounds/enemy-hit.wav"))) -(define-asset player-death-sound (load-audio (scope-datadir "assets/sounds/player-death.wav"))) -(define-asset player-shoot-sound (load-audio (scope-datadir "assets/sounds/player-shoot.wav"))) -(define-asset player-bomb-sound (load-audio (scope-datadir "assets/sounds/player-bomb.wav"))) -(define-asset pollen-release-sound (load-audio (scope-datadir "assets/sounds/pollen-release.wav"))) -(define-asset hehehe-sound (load-audio (scope-datadir "assets/sounds/hehehe.wav"))) -(define-asset alarm-sound (load-audio (scope-datadir "assets/sounds/alarm.wav"))) -(define-asset intro-music (load-audio (scope-datadir "assets/sounds/intro.ogg") #:mode 'stream)) -(define-asset main-music (load-audio (scope-datadir "assets/sounds/main.ogg") #:mode 'stream)) +(define (font-file file-name) + (scope-datadir (string-append "assets/fonts/" file-name))) + +(define (image-file file-name) + (scope-datadir (string-append "assets/images/" file-name))) + +(define (audio-file file-name) + (scope-datadir (string-append "assets/sounds/" file-name))) + +(define-font monogram-font (font-file "monogram_extended.ttf") 12) +(define-image background-image (image-file "background.png")) +(define-image particle-image (image-file "particle.png")) +(define-image darkness-image (image-file "darkness.png")) +(define-image lightness-image (image-file "lightness.png")) +(define-image chickadee-image (image-file "chickadee.png")) +(define-tileset bee-atlas (image-file "bee.png") 32 32) +(define-tileset bullet-atlas (image-file "bullets.png") 16 16) +(define-tileset flower-atlas (image-file "flower.png") 64 64) +(define-tileset popcorn-atlas (image-file "popcorn.png") 32 32) +(define-tileset turret-atlas (image-file "turret.png") 64 64) +(define-tileset moth-atlas (image-file "moth.png") 64 64) +(define-tileset beetle-atlas (image-file "beetle.png") 128 64) +(define-audio explosion-sound (audio-file "explosion.wav")) +(define-audio pickup-sound (audio-file "pickup.wav")) +(define-audio enemy-shoot-sound (audio-file "enemy-shoot.wav")) +(define-audio enemy-hit-sound (audio-file "enemy-hit.wav")) +(define-audio player-death-sound (audio-file "player-death.wav")) +(define-audio player-shoot-sound (audio-file "player-shoot.wav")) +(define-audio player-bomb-sound (audio-file "player-bomb.wav")) +(define-audio pollen-release-sound (audio-file "pollen-release.wav")) +(define-audio hehehe-sound (audio-file "hehehe.wav")) +(define-audio alarm-sound (audio-file "alarm.wav")) +(define-audio intro-music (audio-file "intro.ogg") #:mode 'stream) +(define-audio main-music (audio-file "main.ogg") #:mode 'stream) diff --git a/bonnie-bee/background.scm b/bonnie-bee/background.scm index f374556..9434993 100644 --- a/bonnie-bee/background.scm +++ b/bonnie-bee/background.scm @@ -11,8 +11,8 @@ #:use-module (chickadee scripting) #:use-module (chickadee utils) #:use-module (oop goops) - #:use-module (starling node) - #:use-module (starling node-2d) + #:use-module (catbird node) + #:use-module (catbird node-2d) #:export ( scroll-y)) @@ -94,6 +94,12 @@ void main (void) { (geometry #:getter geometry #:init-thunk make-background-geometry) (mvp-matrix #:getter mvp-matrix #:init-thunk make-identity-matrix4)) +(define-method (default-width (background )) + (texture-width (texture background))) + +(define-method (default-height (background )) + (texture-height (texture background))) + (define-method (render (background ) alpha) (let ((mvp (mvp-matrix background)) (t (texture background))) diff --git a/bonnie-bee/boss.scm b/bonnie-bee/boss.scm index e312d4e..7788f31 100644 --- a/bonnie-bee/boss.scm +++ b/bonnie-bee/boss.scm @@ -11,9 +11,9 @@ #:use-module (chickadee scripting) #:use-module (chickadee utils) #:use-module (oop goops) - #:use-module (starling asset) - #:use-module (starling node) - #:use-module (starling node-2d) + #:use-module (catbird asset) + #:use-module (catbird node) + #:use-module (catbird node-2d) #:export ()) (define-class ( ) @@ -33,7 +33,7 @@ (let loop ((i 0)) (when (< i n) (let ((theta (+ (* (/ tau n) i) offset))) - (add-bullet (bullets (parent boss)) + (add-bullet (& (parent boss) bullets) type (position boss) (vec2 (* (cos theta) speed) @@ -41,7 +41,7 @@ (loop (+ i 1)))))) (define (random-shot speed) (let ((theta (* (- pi) (random:uniform)))) - (add-bullet (bullets (parent boss)) + (add-bullet (& (parent boss) bullets) medium-enemy-bullet (position boss) (vec2 (* (cos theta) speed) @@ -53,9 +53,9 @@ (let ((big-speed 2.0) (little-speed 1.0)) (while (> (health boss) 800) - (let ((d (direction-to boss (player (parent boss))))) - (audio-play (asset-ref enemy-shoot-sound)) - (add-bullet (bullets (parent boss)) + (let ((d (direction-to boss (& (parent boss) player)))) + (audio-play (artifact enemy-shoot-sound)) + (add-bullet (& (parent boss) bullets) large-enemy-bullet (position boss) (vec2* d big-speed)) @@ -67,7 +67,7 @@ (sleep 2.5) (let loop ((theta 0.0)) (unless (<= (health boss) 400) - (audio-play (asset-ref enemy-shoot-sound)) + (audio-play (artifact enemy-shoot-sound)) (repeat 2 (random-shot 0.5)) (circle-shot 2 theta 1.5 large-enemy-bullet) (circle-shot 6 (- theta) 1.0 medium-enemy-bullet) @@ -75,7 +75,7 @@ (loop (+ theta (/ pi 17.1))))) (sleep 2.5) (let loop ((theta 0.0)) - (audio-play (asset-ref enemy-shoot-sound)) + (audio-play (artifact enemy-shoot-sound)) (circle-shot 10 (* theta 2.0) 1.5 large-enemy-bullet) (circle-shot 4 (- theta) 1.0 medium-enemy-bullet) (sleep (* (current-timestep) 10)) @@ -95,6 +95,6 @@ (else #f))) (define-method (on-death (boss )) - (audio-play (asset-ref explosion-sound)) - (add-particle-emitter (particles (particles (parent boss))) + (audio-play (artifact explosion-sound)) + (add-particle-emitter (particles (& (parent boss) particles)) (make-particle-emitter (world-hitbox boss) 20 30))) diff --git a/bonnie-bee/bullet.scm b/bonnie-bee/bullet.scm index 4f79792..5342271 100644 --- a/bonnie-bee/bullet.scm +++ b/bonnie-bee/bullet.scm @@ -1,6 +1,7 @@ (define-module (bonnie-bee bullet) #:use-module (bonnie-bee actor) #:use-module (bonnie-bee assets) + #:use-module (bonnie-bee common) #:use-module (chickadee data quadtree) #:use-module (chickadee graphics sprite) #:use-module (chickadee graphics texture) @@ -10,9 +11,9 @@ #:use-module (chickadee utils) #:use-module (oop goops) #:use-module (srfi srfi-9) - #:use-module (starling asset) - #:use-module (starling node) - #:use-module (starling node-2d) + #:use-module (catbird asset) + #:use-module (catbird node) + #:use-module (catbird node-2d) #:export ( player-bullet? player-primary-bullet? @@ -37,7 +38,7 @@ (hitbox #:getter hitbox #:init-keyword #:hitbox)) (define (bullet-texture bullet) - (texture-atlas-ref (asset-ref bullet-atlas) + (texture-atlas-ref (artifact bullet-atlas) (atlas-index (type bullet)))) (define player-primary-bullet @@ -68,7 +69,7 @@ (define (make-bullet-sprite-batch) (make-sprite-batch (texture-parent - (texture-atlas-ref (asset-ref bullet-atlas) 0)))) + (texture-atlas-ref (artifact bullet-atlas) 0)))) (define (make-vector* size proc) (let ((v (make-vector size))) @@ -104,6 +105,12 @@ (set! (hitboxes bullets) (make-vector* %max-bullets make-null-rect)) (set! (regions bullets) (make-vector* %max-bullets make-null-rect))) +(define-method (default-width (bullets )) + %game-width) + +(define-method (default-height (bullets )) + %game-height) + (define-method (clear-bullets (bullets )) (set! (num-bullets bullets) 0)) diff --git a/bonnie-bee/common.scm b/bonnie-bee/common.scm index 885ab33..6ff21c6 100644 --- a/bonnie-bee/common.scm +++ b/bonnie-bee/common.scm @@ -6,9 +6,9 @@ #:use-module (chickadee math vector) #:use-module (chickadee scripting) #:use-module (oop goops) - #:use-module (starling scene) - #:use-module (starling node) - #:use-module (starling node-2d) + #:use-module (catbird scene) + #:use-module (catbird node) + #:use-module (catbird node-2d) #:export (%window-width %window-height %game-width @@ -23,17 +23,17 @@ (define %game-width 320) (define %game-height 240) -(define-method (set-cameras! (scene )) - (set! (cameras scene) - (list (make - #:resolution (vec2 %game-width %game-height) - #:viewport (make-viewport 0 0 %window-width %window-height - #:clear-color black))))) +;; (define-method (set-cameras! (scene )) +;; (set! (cameras scene) +;; (list (make +;; #:resolution (vec2 %game-width %game-height) +;; #:viewport (make-viewport 0 0 %window-width %window-height +;; #:clear-color black))))) (define (steps n) (* n (current-timestep))) -(define-method (fade-in (scene ) duration) +(define-method (fade-in (scene ) duration) (let ((bg (make #:rank 999 #:texture darkness-image))) @@ -43,7 +43,7 @@ (set! (tint bg) (transparency a)))) (detach bg))) -(define-method (fade-out (scene ) duration) +(define-method (fade-out (scene ) duration) (let ((bg (make #:rank 999 #:texture darkness-image))) diff --git a/bonnie-bee/flower.scm b/bonnie-bee/flower.scm index 5e9eb12..6646ecc 100644 --- a/bonnie-bee/flower.scm +++ b/bonnie-bee/flower.scm @@ -10,9 +10,9 @@ #:use-module (chickadee scripting) #:use-module (chickadee utils) #:use-module (oop goops) - #:use-module (starling asset) - #:use-module (starling node) - #:use-module (starling node-2d) + #:use-module (catbird asset) + #:use-module (catbird node) + #:use-module (catbird node-2d) #:export ( pollen-enabled? enable-pollen! @@ -66,12 +66,12 @@ (let ((p (position flower))) (if (pollen-enabled?) (begin - (audio-play (asset-ref pollen-release-sound)) + (audio-play (artifact pollen-release-sound)) (for-range ((i 16)) (let ((theta (- (* (- (random:uniform) 0.5) (/ pi 3.0)) (/ pi 2.0))) (speed (+ (* (random:uniform) 1.0) 1.0))) - (add-bullet (bullets (parent flower)) + (add-bullet (& (parent flower) bullets) pollen-pickup p (vec2 (* (cos theta) speed) (* (sin theta) speed))))) @@ -81,7 +81,7 @@ #:position (position flower) #:hitbox (make-rect -1.0 -1.0 2.0 2.0)))) (begin - (audio-play (asset-ref explosion-sound)) - (add-particle-emitter (particles (particles (parent flower))) + (audio-play (artifact explosion-sound)) + (add-particle-emitter (particles (& (parent flower) particles)) (make-particle-emitter (make-rect (vec2-x p) (vec2-y p) 1.0 1.0) 10 5)))))) diff --git a/bonnie-bee/game.scm b/bonnie-bee/game.scm index 18b177b..40d5cb6 100644 --- a/bonnie-bee/game.scm +++ b/bonnie-bee/game.scm @@ -20,12 +20,20 @@ #:use-module (chickadee math vector) #:use-module (chickadee scripting) #:use-module (oop goops) - #:use-module (starling asset) - #:use-module (starling kernel) - #:use-module (starling node) - #:use-module (starling node-2d) - #:use-module (starling scene) - #:export ()) + #:use-module (catbird) + #:use-module (catbird asset) + #:use-module (catbird kernel) + #:use-module (catbird observer) + #:use-module (catbird mode) + #:use-module (catbird node) + #:use-module (catbird node-2d) + #:use-module (catbird scene) + #:export (make-game-scene)) + + +;;; +;;; Shadow label +;;; (define %text-color (rgb #xfee761)) @@ -37,7 +45,7 @@ (make