diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2021-10-21 08:28:40 -0400 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2021-10-21 08:28:40 -0400 |
commit | 0ef4a323549ea72f4c5c3df17ac78ceda069ed03 (patch) | |
tree | 3831dd2459b626922e897d85499e359feb1f8782 | |
parent | ba887d36cd96e188771eda44ddfb7c31c9811fc0 (diff) |
Add real boss fight.
-rw-r--r-- | bonnie-bee/actor.scm | 1 | ||||
-rw-r--r-- | bonnie-bee/boss.scm | 63 | ||||
-rw-r--r-- | bonnie-bee/bullet.scm | 2 | ||||
-rw-r--r-- | bonnie-bee/game.scm | 100 | ||||
-rw-r--r-- | bonnie-bee/player.scm | 3 |
5 files changed, 117 insertions, 52 deletions
diff --git a/bonnie-bee/actor.scm b/bonnie-bee/actor.scm index 1e21144..90938c8 100644 --- a/bonnie-bee/actor.scm +++ b/bonnie-bee/actor.scm @@ -22,6 +22,7 @@ dead? out-of-bounds? <damageable> + health points damage on-death diff --git a/bonnie-bee/boss.scm b/bonnie-bee/boss.scm index d19f2c2..7e4d375 100644 --- a/bonnie-bee/boss.scm +++ b/bonnie-bee/boss.scm @@ -3,6 +3,7 @@ #:use-module (bonnie-bee assets) #:use-module (bonnie-bee bullet) #:use-module (chickadee audio) + #:use-module (chickadee game-loop) #:use-module (chickadee graphics particles) #:use-module (chickadee math) #:use-module (chickadee math rect) @@ -15,7 +16,8 @@ #:use-module (starling node-2d) #:export (<boss>)) -(define-class <boss> (<grounded> <damageable> <actor>)) +(define-class <boss> (<grounded> <damageable> <actor>) + (invincible? #:accessor invincible? #:init-value #t)) (define-method (on-boot (boss <boss>)) (attach-to boss @@ -23,14 +25,69 @@ #:texture beetle-image #:origin (vec2 64.0 32.0)))) +(define-method (on-enter (boss <boss>)) + (define (circle-shot n offset speed type) + (let loop ((i 0)) + (when (< i n) + (let ((theta (+ (* (/ tau n) i) offset))) + (add-bullet (bullets (parent boss)) + type + (position boss) + (vec2 (* (cos theta) speed) + (* (sin theta) speed))) + (loop (+ i 1)))))) + (define (random-shot speed) + (let ((theta (* (- pi) (random:uniform)))) + (add-bullet (bullets (parent boss)) + medium-enemy-bullet + (position boss) + (vec2 (* (cos theta) speed) + (* (sin theta) speed))))) + (next-method) + (run-script boss + (sleep 5.0) + (set! (invincible? boss) #f) + (let ((big-speed 2.0) + (little-speed 1.0)) + (while (> (health boss) 2000) + (let ((d (direction-to boss (player (parent boss))))) + (add-bullet (bullets (parent boss)) + large-enemy-bullet + (position boss) + (vec2* d big-speed)) + (let loop ((i 0)) + (when (< i 16) + (audio-play (asset-ref enemy-shoot-sound)) + (random-shot little-speed) + (sleep (* (current-timestep) 2.0)) + (loop (+ i 1))))))) + (sleep 2.5) + (let loop ((theta 0.0)) + (unless (<= (health boss) 1000) + (audio-play (asset-ref 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) + (sleep (* (current-timestep) 10)) + (loop (+ theta (/ pi 17.1))))) + (sleep 2.5) + (let loop ((theta 0.0)) + (audio-play (asset-ref 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)) + (loop (+ theta (/ pi 37.1)))))) + (define-method (on-collide (boss <boss>) (bullet <bullet>)) (cond ((player-primary-bullet? bullet) - (damage boss 1) + (unless (invincible? boss) + (damage boss 1)) (kill-bullet bullet) #t) ((player-bomb-bullet? bullet) - (damage boss 10) + (unless (invincible? boss) + (damage boss 10)) (kill-bullet bullet)) (else #f))) diff --git a/bonnie-bee/bullet.scm b/bonnie-bee/bullet.scm index 2cd722b..46c995c 100644 --- a/bonnie-bee/bullet.scm +++ b/bonnie-bee/bullet.scm @@ -54,7 +54,7 @@ (define medium-enemy-bullet (make <bullet-type> #:name 'medium-enemy #:atlas-index 1 - #:hitbox (make-rect -2.0 -2.0 4.0 4.0))) + #:hitbox (make-rect -1.25 -1.25 2.5 2.5))) (define small-enemy-bullet (make <bullet-type> #:name 'small-enemy #:atlas-index 2 diff --git a/bonnie-bee/game.scm b/bonnie-bee/game.scm index b5d1eaf..7957a10 100644 --- a/bonnie-bee/game.scm +++ b/bonnie-bee/game.scm @@ -257,39 +257,40 @@ (spawn game (make-popcorn (vec2-copy spawn-point) velocity)) (sleep delay) (loop (+ i 1))))) - (spawn game (make-flower (vec2 (- %game-width 64.0) (+ %game-height 32.0)))) - (popcorn-line 5 (vec2 64.0 (+ %game-height 16.0)) - (vec2 0.0 -2.0) 0.2) - (sleep 0.5) - (popcorn-line 5 (vec2 (- %game-width 64.0) (+ %game-height 16.0)) - (vec2 0.0 -2.0) 0.2) - (sleep 0.5) - (spawn game (make-flower (vec2 64.0 (+ %game-height 32.0)))) - (popcorn-line 5 (vec2 (/ %game-width 2.0) (+ %game-height 16.0)) - (vec2 0.0 -2.0) 0.2) - (sleep 1.0) - (run-script game - (popcorn-line 10 (vec2 -16.0 220.0) - (vec2 3.0 -0.5) 0.2)) - (popcorn-line 10 (vec2 (+ %game-width 16.0) 200.0) - (vec2 -3.0 -0.5) 0.2) - (spawn game (make-flower (vec2 (/ %game-width 2.0) (+ %game-height 32.0)))) - (sleep 1.0) - (run-script game - (popcorn-line 30 (vec2 -16.0 220.0) - (vec2 2.0 -2.0) 0.2)) - (run-script game - (popcorn-line 30 (vec2 (+ %game-width 16.0) 220.0) - (vec2 -2.0 -2.0) 0.2)) - (spawn game (make-flower (vec2 128.0 (+ %game-height 32.0)))) - (sleep 2.0) - (run-script game - (popcorn-line 20 (vec2 -16.0 20.0) - (vec2 2.0 2.0) 0.2)) - (spawn game (make-flower (vec2 256.0 (+ %game-height 32.0)))) - (popcorn-line 20 (vec2 (+ %game-width 16.0) 20.0) - (vec2 -2.0 2.0) 0.2) - (sleep 3.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)) + (vec2 0.0 -2.0) 0.2) + (sleep 0.5) + (popcorn-line 5 (vec2 (- %game-width 64.0) (+ %game-height 16.0)) + (vec2 0.0 -2.0) 0.2) + (sleep 0.5) + (spawn game (make-flower (vec2 64.0 (+ %game-height 32.0)))) + (popcorn-line 5 (vec2 (/ %game-width 2.0) (+ %game-height 16.0)) + (vec2 0.0 -2.0) 0.2) + (sleep 1.0) + (run-script game + (popcorn-line 10 (vec2 -16.0 220.0) + (vec2 3.0 -0.5) 0.2)) + (popcorn-line 10 (vec2 (+ %game-width 16.0) 200.0) + (vec2 -3.0 -0.5) 0.2) + (spawn game (make-flower (vec2 (/ %game-width 2.0) (+ %game-height 32.0)))) + (sleep 1.0) + (run-script game + (popcorn-line 30 (vec2 -16.0 220.0) + (vec2 2.0 -2.0) 0.2)) + (run-script game + (popcorn-line 30 (vec2 (+ %game-width 16.0) 220.0) + (vec2 -2.0 -2.0) 0.2)) + (spawn game (make-flower (vec2 128.0 (+ %game-height 32.0)))) + (sleep 2.0) + (run-script game + (popcorn-line 20 (vec2 -16.0 20.0) + (vec2 2.0 2.0) 0.2)) + (spawn game (make-flower (vec2 256.0 (+ %game-height 32.0)))) + (popcorn-line 20 (vec2 (+ %game-width 16.0) 20.0) + (vec2 -2.0 2.0) 0.2) + (sleep 3.0)) ;; Wave 2 ;; popcorn that shoots, more flowers @@ -304,15 +305,20 @@ (tween 1.0 15.0 0.0 (lambda (speed) (change-scroll-speed game speed))) - (spawn game (make <boss> + (let ((boss (make <boss> #:name 'boss #:rank 2 - #:position (vec2 (/ %game-width 2.0) (- %game-height 64.0)) + #:position (vec2 (/ %game-width 2.0) (+ %game-height 32.0)) #:hitbox (make-rect -64.0 -32.0 128.0 64.0) - #:health 100 - #:points 1000000)) + #: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))) + (set! (invincible? (player game)) #t) (game-complete game) ;; (let loop ((i 0)) @@ -359,17 +365,9 @@ (lambda (volume) (set-source-volume! (music-source game) volume))) (source-stop (music-source game)) - (set-source-volume! (music-source game) 1.0) (play-music game intro-music) - (change-state game 'game-complete) - (stop-scripts game) - (run-script game - (sleep 1.0) - (spawn game (make-flower (vec2 (/ %game-width 4) 160.0))) - (sleep 1.0) - (spawn game (make-flower (vec2 (/ %game-width 2) 160.0))) - (sleep 1.0) - (spawn game (make-flower (vec2 (- %game-width (/ %game-width 4)) 160.0)))) + (set-source-volume! (music-source game) 1.0) + (change-state game 'pre-game-complete) (let ((p (player game))) (stop-scripts p) (set! (shoot? p) #f) @@ -377,6 +375,14 @@ (set! (move-right? p) #f) (set! (move-down? p) #f) (set! (move-up? p) #f)) + (sleep 1.0) + (spawn game (make-flower (vec2 (/ %game-width 4) 160.0))) + (sleep 1.0) + (spawn game (make-flower (vec2 (/ %game-width 2) 160.0))) + (sleep 1.0) + (spawn game (make-flower (vec2 (- %game-width (/ %game-width 4)) 160.0))) + (sleep 1.0) + (change-state game 'game-complete) (let ((group (make <node-2d> #:name 'game-complete #:rank 5))) diff --git a/bonnie-bee/player.scm b/bonnie-bee/player.scm index 6f6cd91..78eafc0 100644 --- a/bonnie-bee/player.scm +++ b/bonnie-bee/player.scm @@ -20,6 +20,7 @@ move-down? move-up? shoot? + invincible? speed lives pollen @@ -38,7 +39,7 @@ (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)) - (speed #:accessor speed #:init-value 2.5) + (speed #:accessor speed #:init-value 1.8) (lives #:accessor lives #:init-value 3) (invincible? #:accessor invincible? #:init-value #f) (pollen #:accessor pollen #:init-value 0) |