summaryrefslogtreecommitdiff
path: root/bonnie-bee/game.scm
diff options
context:
space:
mode:
Diffstat (limited to 'bonnie-bee/game.scm')
-rw-r--r--bonnie-bee/game.scm272
1 files changed, 230 insertions, 42 deletions
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 <moth>
+ #: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 <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 <boss>
- #: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 <boss>
+ #: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 <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 <actor>)
(memq (name child) '(game-over game-complete tutorial)))
@@ -357,6 +528,8 @@
(reset-game game))
(define-method (game-complete (game <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 <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 <node-2d>
#:name 'game-over
#:rank 5)))