From 7e76d1c2005435c412ff96bf3e0f0f6be12c22c5 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 23 Oct 2021 19:57:53 -0400 Subject: Add ability to pause and add a warning before the boss. --- bonnie-bee/game.scm | 81 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 18 deletions(-) (limited to 'bonnie-bee') diff --git a/bonnie-bee/game.scm b/bonnie-bee/game.scm index b868cd2..4d02490 100644 --- a/bonnie-bee/game.scm +++ b/bonnie-bee/game.scm @@ -202,7 +202,6 @@ (flower-7 (make-flower (vec2 220.0 151.0))) (flower-8 (make-flower (vec2 290.0 129.0)))) (define (shoot-at flower) - (audio-play (asset-ref enemy-shoot-sound)) (add-bullet (bullets game) medium-enemy-bullet (position popcorn) @@ -432,7 +431,9 @@ (tween 0.5 -2.0 0.0 (lambda (dy) (change-velocity popcorn 0.0 dy))) - (let ((d (direction-to popcorn (player game)))) + (let ((d (vec2-normalize + (vec2- (vec2+ (position (player game)) (vec2 0.0 16.0)) + (position popcorn))))) (tween 0.5 0.0 4.0 (lambda (speed) (change-velocity popcorn (* (vec2-x d) speed) (* (vec2-y d) speed))))))) @@ -504,9 +505,22 @@ (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 14.0)) + (sleep 7.0)) ;; Boss (unless (getenv "SKIP_BOSS") + (run-script game + (let ((warning (make + #:name 'warning + #:rank 9 + #:position (vec2 (/ %game-width 2.0) (/ %game-height 2.0)) + #:font monogram-font + #:text "WARNING!! BIG OL' BAD THING AHEAD!" + #:align 'center + #:color %text-color))) + (attach-to game warning) + (blink warning 15 0.25) + (detach warning))) + (sleep 7.0) (spawn game (make #:name 'boss #:rank 2 @@ -535,7 +549,8 @@ (show (& game hud-pollen)) (for-each-child (lambda (child) (when (or (is-a? child ) - (memq (name child) '(game-over game-complete tutorial))) + (memq (name child) + '(game-over game-complete tutorial warning))) (detach child))) game) (spawn game @@ -635,12 +650,43 @@ #:align 'center #:color %text-color)))) +(define-method (toggle-pause (game )) + (if (paused? game) + (begin + (detach (& game pause-overlay)) + (resume game)) + (let ((overlay (make + #:name 'pause-overlay + #:rank 99))) + (pause game) + (attach-to overlay + (make + #:texture darkness-image + #:tint (transparency 0.4)) + (make + #:position (vec2 (/ %game-width 2.0) (/ %game-height 2.0)) + #:font monogram-font + #:text "PAUSED" + #:align 'center + #:vertical-align 'center + #:color %text-color)) + (attach-to game overlay)))) + +(define-method (play-again (game )) + (run-script game + (tween 0.5 1.0 0.0 + (lambda (volume) + (set-source-volume! (music-source game) volume))) + (source-stop (music-source game)) + (set-source-volume! (music-source game) 1.0)) + (run-script game + (fade-out game 1.0) + (reset-game game))) + (define-method (on-key-press (game ) key modifiers repeat?) (case (state game) ((play) (case key - ((q) - (pop-scene (current-kernel))) ((left) (set! (move-left? (player game)) #t)) ((right) @@ -652,24 +698,23 @@ ((z) (set! (shoot? (player game)) #t)) ((x) - (bomb (player game))))) - ((game-over game-complete) - (case key + (bomb (player game))) ((q) (pop-scene (current-kernel))) ((return) - (run-script game - (tween 1.0 1.0 0.0 - (lambda (volume) - (set-source-volume! (music-source game) volume))) - (source-stop (music-source game))) - (run-script game - (fade-out game 1.0) - (reset-game game))))) + (toggle-pause game)))) ((intro) (case key ((q) - (pop-scene (current-kernel))))))) + (pop-scene (current-kernel))) + ((return) + (toggle-pause game)))) + ((game-over game-complete) + (case key + ((q) + (pop-scene (current-kernel))) + ((return) + (play-again game)))))) (define-method (on-key-release (game ) key modifiers) (case (state game) -- cgit v1.2.3