From 10b02b1fb15b76c8037760f2a3e8dc3601759f28 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 21 Oct 2021 19:33:42 -0400 Subject: Add roughly finished level. --- .dir-locals.el | 3 +- assets/images/moth.png | Bin 1337 -> 1356 bytes assets/images/moth.xcf | Bin 6853 -> 6628 bytes bonnie-bee/boss.scm | 4 +- bonnie-bee/bullet.scm | 2 +- bonnie-bee/flower.scm | 5 +- bonnie-bee/game.scm | 272 +++++++++++++++++++++++++++++++++++++++++-------- bonnie-bee/moth.scm | 42 ++++++++ bonnie-bee/player.scm | 3 +- bonnie-bee/turret.scm | 2 +- 10 files changed, 284 insertions(+), 49 deletions(-) create mode 100644 bonnie-bee/moth.scm diff --git a/.dir-locals.el b/.dir-locals.el index bf81028..78f84d5 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,3 +1,4 @@ ((scheme-mode . - ((eval . (put 'with-agenda 'scheme-indent-function 1))))) + ((eval . (put 'with-agenda 'scheme-indent-function 1)) + (eval . (put 'repeat 'scheme-indent-function 1))))) diff --git a/assets/images/moth.png b/assets/images/moth.png index e46c84a..47074ba 100644 Binary files a/assets/images/moth.png and b/assets/images/moth.png differ diff --git a/assets/images/moth.xcf b/assets/images/moth.xcf index 0cd0305..988c903 100644 Binary files a/assets/images/moth.xcf and b/assets/images/moth.xcf differ diff --git a/bonnie-bee/boss.scm b/bonnie-bee/boss.scm index 7e4d375..885f0bc 100644 --- a/bonnie-bee/boss.scm +++ b/bonnie-bee/boss.scm @@ -49,7 +49,7 @@ (set! (invincible? boss) #f) (let ((big-speed 2.0) (little-speed 1.0)) - (while (> (health boss) 2000) + (while (> (health boss) 800) (let ((d (direction-to boss (player (parent boss))))) (add-bullet (bullets (parent boss)) large-enemy-bullet @@ -63,7 +63,7 @@ (loop (+ i 1))))))) (sleep 2.5) (let loop ((theta 0.0)) - (unless (<= (health boss) 1000) + (unless (<= (health boss) 400) (audio-play (asset-ref enemy-shoot-sound)) (repeat 2 (random-shot 0.5)) (circle-shot 2 theta 1.5 large-enemy-bullet) diff --git a/bonnie-bee/bullet.scm b/bonnie-bee/bullet.scm index 46c995c..1ec40b5 100644 --- a/bonnie-bee/bullet.scm +++ b/bonnie-bee/bullet.scm @@ -63,7 +63,7 @@ ;; Yeah... pollen is a bullet. Didn't you know that?? (define pollen-pickup (make #:name 'pollen #:atlas-index 6 - #:hitbox (make-rect -10.0 -10.0 20.0 20.0))) + #:hitbox (make-rect -16.0 -16.0 32.0 32.0))) (define (make-bullet-sprite-batch) (make-sprite-batch diff --git a/bonnie-bee/flower.scm b/bonnie-bee/flower.scm index 2c018e9..13d8c10 100644 --- a/bonnie-bee/flower.scm +++ b/bonnie-bee/flower.scm @@ -38,10 +38,13 @@ (define-method (on-collide (flower ) (bullet )) (cond - ((player-bullet? bullet) + ((player-primary-bullet? bullet) (damage flower 1) (kill-bullet bullet) #t) + ((player-bomb-bullet? bullet) + (damage flower 5) + (kill-bullet bullet)) ((and (not (pollen-enabled?)) (enemy-bullet? bullet)) (damage flower 1000) (kill-bullet bullet)) diff --git a/bonnie-bee/game.scm b/bonnie-bee/game.scm index 4aa99a5..4687a33 100644 --- a/bonnie-bee/game.scm +++ b/bonnie-bee/game.scm @@ -6,14 +6,16 @@ #:use-module (bonnie-bee bullet) #:use-module (bonnie-bee common) #:use-module (bonnie-bee flower) + #:use-module (bonnie-bee moth) #:use-module (bonnie-bee player) - #:use-module (bonnie-bee turret) #:use-module (bonnie-bee popcorn) + #:use-module (bonnie-bee turret) #:use-module (chickadee) #:use-module (chickadee audio) #:use-module (chickadee data quadtree) #:use-module (chickadee graphics color) #:use-module (chickadee graphics particles) + #:use-module (chickadee math) #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (chickadee scripting) @@ -97,7 +99,7 @@ #:rank 1 #:position p #:hitbox (make-rect -32.0 -32.0 64.0 64.0) - #:health 50 + #:health 24 #:points 200))) (run-script turret (sleep (steps 1)) @@ -119,7 +121,7 @@ #:rank 1 #:position p #:hitbox (make-rect -32.0 -32.0 64.0 64.0) - #:health 30 + #:health 24 #:points 100)) (define* (make-popcorn p #:optional (v (vec2 0.0 0.0))) @@ -131,6 +133,15 @@ #:health 1 #:points 10)) +(define (make-moth p) + (make + #:rank 2 + #:position p + #:velocity (vec2 0.0 -2.0) + #:hitbox (make-rect -28.0 -19.0 56.0 38.0) + #:health 20 + #:points 300)) + (define-method (change-state (game ) new-state) (set! (state game) new-state)) @@ -251,12 +262,17 @@ (tutorial "godspeed you, little bee!" #f)) (change-scroll-speed game 15.0) ;; Wave 1 - (define (popcorn-line n spawn-point velocity delay) + (define* (popcorn-line n spawn-point velocity delay #:optional script) (let loop ((i 0)) (when (< i n) - (spawn game (make-popcorn (vec2-copy spawn-point) velocity)) + (let ((popcorn (make-popcorn (vec2-copy spawn-point) velocity))) + (spawn game popcorn) + (when script + (run-script popcorn (script popcorn)))) (sleep delay) (loop (+ i 1))))) + (define (spawn-flower x) + (spawn game (make-flower (vec2 x (+ %game-height 32.0))))) (unless (getenv "SKIP_WAVE1") (spawn game (make-flower (vec2 (- %game-width 64.0) (+ %game-height 32.0)))) (popcorn-line 5 (vec2 64.0 (+ %game-height 16.0)) @@ -292,54 +308,209 @@ (vec2 -2.0 2.0) 0.2) (sleep 3.0)) ;; Wave 2 - ;; popcorn that shoots, turrets, more flowers - + ;; kamikaze popcorn, turrets, more flowers + (define (spawn-turret x) + (spawn game (make-turret (vec2 x (+ %game-height 32.0))))) + (define (shoot-down enemy) + (sleep 0.2) + (repeat 10 + (add-bullet (bullets game) + medium-enemy-bullet + (position enemy) + (vec2 0.0 -2.0)) + (sleep 0.1))) + (unless (getenv "SKIP_WAVE2") + (popcorn-line 10 (vec2 (+ %game-width 16.0) 200.0) + (vec2 -3.0 -0.5) 0.2) + (spawn-flower 32.0) + (sleep 1.0) + (spawn-flower 270.0) + (sleep 1.0) + (spawn-flower 128.0) + (sleep 1.0) + (spawn-flower 77.0) + (sleep 1.0) + (spawn-flower 303.0) + (sleep 1.0) + (spawn-flower 153.0) + (sleep 1.0) + (spawn-flower 209.0) + (popcorn-line 10 (vec2 -16.0 200.0) + (vec2 3.0 -0.5) 0.2) + (sleep 1.0) + (spawn-turret 32.0) + (sleep 1.0) + (spawn-flower 270.0) + (sleep 1.0) + (spawn-flower 128.0) + (sleep 1.0) + (spawn-flower 77.0) + (sleep 1.0) + (spawn-flower 303.0) + (sleep 1.0) + (spawn-flower 153.0) + (sleep 1.0) + (spawn-flower 209.0) + (sleep 1.0) + (spawn-flower 32.0) + (popcorn-line 10 (vec2 (+ %game-width 16.0) 200.0) + (vec2 -3.0 -0.5) 0.2) + (sleep 1.0) + (spawn-turret 270.0) + (sleep 1.0) + (spawn-flower 128.0) + (sleep 1.0) + (spawn-flower 77.0) + (sleep 1.0) + (spawn-turret 303.0) + (sleep 1.0) + (spawn-flower 153.0) + (sleep 1.0) + (spawn-turret 209.0) + (sleep 1.0) + (spawn-turret 32.0) + (popcorn-line 10 (vec2 -16.0 200.0) + (vec2 3.0 -0.5) 0.2) + (sleep 1.0) + (spawn-turret 270.0) + (sleep 1.0) + (spawn-flower 128.0) + (sleep 1.0) + (spawn-turret 77.0) + (sleep 1.0) + (spawn-turret 303.0) + (sleep 1.0) + (spawn-flower 153.0) + (sleep 1.0) + (spawn-turret 209.0) + (popcorn-line 10 (vec2 (+ %game-width 16.0) 200.0) + (vec2 -3.0 -0.5) 0.2) + (sleep 8.0) + (run-script game + (spawn-turret (* %game-width 0.25)) + (sleep 2.0) + (spawn-turret (* %game-width 0.75)) + (sleep 2.0) + (spawn-turret (* %game-width 0.25)) + (sleep 2.0) + (spawn-turret (* %game-width 0.75)) + (sleep 2.0) + (spawn-turret (* %game-width 0.25))) + (repeat 100 + (let ((popcorn (make-popcorn (vec2 (+ (/ %game-width 2.0) + (* (/ %game-width 4.0) (- (random:uniform) 0.5))) + (+ %game-height 16.0)) + (vec2 0.0 -2.0)))) + (spawn game popcorn) + (run-script popcorn + (sleep 0.5) + (tween 0.5 -2.0 0.0 + (lambda (dy) + (change-velocity popcorn 0.0 dy))) + (let ((d (direction-to popcorn (player game)))) + (tween 0.5 0.0 4.0 + (lambda (speed) + (change-velocity popcorn (* (vec2-x d) speed) (* (vec2-y d) speed))))))) + (sleep 0.1)) + (sleep 8.0)) ;; Wave 3 - ;; moths, more turrets, more popcorn, more flowers - + ;; moths, more turrets, more flowers + (define (spawn-moth p) + (let ((moth (make-moth p))) + (spawn game moth) + (run-script moth + (sleep 0.2) + (tween 1.0 -2.0 0.0 + (lambda (dy) + (change-velocity moth 0.0 dy))) + (change-velocity moth 0.0 0.0) + (let loop ((i 0)) + (when (< i 8) + (let* ((arc-start (- (* pi 1.5) 0.2)) + (arc-end (+ (* pi 1.5) 0.2)) + (n 8) + (arc-step (/ (- arc-end arc-start) n)) + (speed 1.9)) + (audio-play (asset-ref enemy-shoot-sound)) + (let arc-loop ((j 0)) + (when (< j n) + (let ((theta (+ arc-start (* j arc-step)))) + (add-bullet (bullets game) + medium-enemy-bullet + (position moth) + (vec2 (* (cos theta) speed) + (* (sin theta) speed)))) + (arc-loop (+ j 1))))) + (sleep (* (current-timestep) 5)) + (loop (+ i 1)))) + (tween 1.0 0.0 -2.0 + (lambda (dy) + (change-velocity moth 0.0 dy)))))) + (unless (getenv "SKIP_WAVE3") + (spawn-moth (vec2 (* %game-width 0.5) (+ %game-height 16.0))) + (spawn-flower (* %game-width 0.125)) + (spawn-flower (* %game-width 0.875)) + (sleep 4.0) + (spawn-moth (vec2 (* %game-width 0.25) (+ %game-height 16.0))) + (spawn-flower (* %game-width 0.375)) + (spawn-turret (* %game-width 0.875)) + (sleep 2.0) + (spawn-moth (vec2 (* %game-width 0.5) (+ %game-height 16.0))) + (sleep 2.0) + (spawn-moth (vec2 (* %game-width 0.75) (+ %game-height 16.0))) + (sleep 2.0) + (spawn-moth (vec2 (* %game-width 0.5) (+ %game-height 16.0))) + (spawn-flower (* %game-width 0.625)) + (spawn-turret (* %game-width 0.375)) + (sleep 1.0) + (spawn-moth (vec2 (* %game-width 0.25) (+ %game-height 16.0))) + (sleep 2.0) + (spawn-moth (vec2 (* %game-width 0.5) (+ %game-height 16.0))) + (sleep 1.0) + (spawn-moth (vec2 (* %game-width 0.75) (+ %game-height 16.0))) + (sleep 2.5) + (spawn-moth (vec2 (* %game-width 0.25) (+ %game-height 16.0))) + (spawn-moth (vec2 (* %game-width 0.75) (+ %game-height 16.0))) + (sleep 3.0) + (spawn-moth (vec2 (* %game-width 0.5) (+ %game-height 16.0))) + (spawn-flower (* %game-width 0.125)) + (spawn-turret (* %game-width 0.625)) + (spawn-flower (* %game-width 0.875)) + (sleep 2.0) + (spawn-moth (vec2 (* %game-width 0.25) (+ %game-height 16.0))) + (spawn-moth (vec2 (* %game-width 0.5) (+ %game-height 16.0))) + (spawn-moth (vec2 (* %game-width 0.75) (+ %game-height 16.0))) + (sleep 6.0)) ;; Boss (tween 1.0 15.0 0.0 (lambda (speed) (change-scroll-speed game speed))) - (let ((boss (make - #:name 'boss - #:rank 2 - #:position (vec2 (/ %game-width 2.0) (+ %game-height 32.0)) - #:hitbox (make-rect -64.0 -32.0 128.0 64.0) - #:health 3000 - #:points 1000000))) - (spawn game boss) - (change-velocity boss 0.0 -1.0) - (sleep 1.4) - (change-velocity boss 0.0 0.0)) - ;; Victory - (wait-until (dead? (& game boss))) + (unless (getenv "SKIP_BOSS") + (let ((boss (make + #:name 'boss + #:rank 2 + #:position (vec2 (/ %game-width 2.0) (+ %game-height 32.0)) + #:hitbox (make-rect -64.0 -32.0 128.0 64.0) + #:health 1200 + #:points 1000000))) + (spawn game boss) + (change-velocity boss 0.0 -1.0) + (sleep 1.4) + (change-velocity boss 0.0 0.0)) + (wait-until (dead? (& game boss)))) + ;; Victory! (set! (invincible? (player game)) #t) - (game-complete game) - - ;; (let loop ((i 0)) - ;; (when (< i 2) - ;; (spawn game - ;; (make-turret (vec2 (random 320) 240))) - ;; (loop (+ i 1)))) - - ;; (let loop ((i 0)) - ;; (when (< i 8) - ;; (spawn game - ;; (make-flower (vec2 (random 320) (random 240)))) - ;; (loop (+ i 1)))) - - ;; (forever - ;; (spawn game - ;; (make-popcorn (vec2 (random 320) (+ 120 (random 120))))) - ;; (sleep 2.0)) - )) + (add-to-score (player game) (* (lives (player game)) 500000)) + (game-complete game))) (define-method (reset-game (game )) + (stop-scripts game) (disable-pollen!) (change-scroll-speed game 0.0) (clear-bullets (bullets game)) (quadtree-clear! (quadtree game)) + (show (& game hud-lives)) + (show (& game hud-pollen)) (for-each-child (lambda (child) (when (or (is-a? child ) (memq (name child) '(game-over game-complete tutorial))) @@ -357,6 +528,8 @@ (reset-game game)) (define-method (game-complete (game )) + (hide (& game hud-lives)) + (hide (& game hud-pollen)) (tween 1.0 1.0 0.0 (lambda (volume) (set-source-volume! (music-source game) volume))) @@ -372,10 +545,13 @@ (set! (move-down? p) #f) (set! (move-up? p) #f)) (sleep 1.0) + (audio-play (asset-ref pickup-sound)) (spawn game (make-flower (vec2 (/ %game-width 4) 160.0))) (sleep 1.0) + (audio-play (asset-ref pickup-sound)) (spawn game (make-flower (vec2 (/ %game-width 2) 160.0))) (sleep 1.0) + (audio-play (asset-ref pickup-sound)) (spawn game (make-flower (vec2 (- %game-width (/ %game-width 4)) 160.0))) (sleep 1.0) (change-state game 'game-complete) @@ -393,9 +569,17 @@ #:position (vec2 (/ %game-width 2.0) (- (/ %game-height 2.0) 20.0)) #:font monogram-font #:text "press ENTER to play again" - #:align 'center)))) + #:align 'center))) + (forever + (add-bullet (bullets game) + pollen-pickup + (vec2 (random %game-width) (+ %game-height 0.0)) + (vec2 0.0 (- (+ (random:uniform) 0.5)))) + (sleep 0.1))) (define-method (game-over (game )) + (hide (& game hud-lives)) + (hide (& game hud-pollen)) (change-state game 'game-over) (stop-scripts game) (let ((p (player game))) @@ -406,6 +590,10 @@ (set! (move-right? p) #f) (set! (move-down? p) #f) (set! (move-up? p) #f)) + (run-script game + (tween 1.0 (scroll-speed game) 0.0 + (lambda (speed) + (change-scroll-speed game speed)))) (let ((group (make #:name 'game-over #:rank 5))) diff --git a/bonnie-bee/moth.scm b/bonnie-bee/moth.scm new file mode 100644 index 0000000..8f4ed5f --- /dev/null +++ b/bonnie-bee/moth.scm @@ -0,0 +1,42 @@ +(define-module (bonnie-bee moth) + #:use-module (bonnie-bee actor) + #:use-module (bonnie-bee assets) + #:use-module (bonnie-bee bullet) + #:use-module (chickadee audio) + #:use-module (chickadee graphics particles) + #:use-module (chickadee math) + #:use-module (chickadee math rect) + #:use-module (chickadee math vector) + #: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) + #:export ()) + +(define-class ( )) + +(define-method (on-boot (moth )) + (attach-to moth + (make + #:texture moth-image + #:origin (vec2 32.0 32.0)))) + +(define-method (on-collide (moth ) (bullet )) + (cond + ((player-primary-bullet? bullet) + (damage moth 1) + (kill-bullet bullet) + #t) + ((player-bomb-bullet? bullet) + (damage moth 10) + (kill-bullet bullet)) + (else #f))) + +(define-method (on-death (moth )) + (audio-play (asset-ref explosion-sound)) + (let ((p (position moth))) + (add-particle-emitter (particles (particles (parent moth))) + (make-particle-emitter (make-rect (vec2-x p) (vec2-y p) 1.0 1.0) + 4 3)))) diff --git a/bonnie-bee/player.scm b/bonnie-bee/player.scm index 78eafc0..10242c7 100644 --- a/bonnie-bee/player.scm +++ b/bonnie-bee/player.scm @@ -38,7 +38,7 @@ (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 (steps 2)) + (shot-interval #:getter shot-interval #:init-form (steps 2)) (speed #:accessor speed #:init-value 1.8) (lives #:accessor lives #:init-value 3) (invincible? #:accessor invincible? #:init-value #f) @@ -86,6 +86,7 @@ (define-method (lose-life (player )) (unless (invincible? player) (set! (lives player) (max (- (lives player) 1) 0)) + (set! (pollen player) 0) (set! (invincible? player) #t) (audio-play (asset-ref player-death-sound)) (run-script player diff --git a/bonnie-bee/turret.scm b/bonnie-bee/turret.scm index 29a3654..9474c65 100644 --- a/bonnie-bee/turret.scm +++ b/bonnie-bee/turret.scm @@ -30,7 +30,7 @@ (kill-bullet bullet) #t) ((player-bomb-bullet? bullet) - (damage turret 10) + (damage turret 5) (kill-bullet bullet)) (else #f))) -- cgit v1.2.3