summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-10-25 08:55:44 -0400
committerDavid Thompson <dthompson2@worcester.edu>2023-10-25 08:55:44 -0400
commitfc9ddd1a28ae7b20bcb92d2021055d3f8df6d9c0 (patch)
tree17394855665f448598773cd4073e02edca961e09
parent3c38445f3c04b43641347a609e1eb6b1dc2396cb (diff)
Add paused, game-win states.
-rw-r--r--game.scm47
1 files changed, 36 insertions, 11 deletions
diff --git a/game.scm b/game.scm
index f3cafdd..30e04fb 100644
--- a/game.scm
+++ b/game.scm
@@ -289,7 +289,7 @@
(audio-play audio)
(vector-set! sound 0 (modulo (+ i 1) (vector-length vec)))))))
- ;; intro, play, game-over, game-won
+ ;; intro, play, paused, game-over, game-win
(define *game-state* 'play)
;; Screen size stuff
@@ -714,6 +714,7 @@
(define (spawn-enemy-a x y)
(define (script enemy)
(let ((speed 2.0))
+ (wait 60)
(let loop ((theta 0.0))
(let ((dx (* (cos theta) speed))
(dy (* (sin theta) speed))
@@ -920,6 +921,16 @@
(set-font! context "bold 24px monospace")
(set-text-align! context "center")
(fill-text context "GAME OVER" (/ game-width 2.0) (/ game-height 2.0)))
+ ('game-win
+ (set-fill-color! context "#ffffff")
+ (set-font! context "bold 24px monospace")
+ (set-text-align! context "center")
+ (fill-text context "WELL DONE" (/ game-width 2.0) (/ game-height 2.0)))
+ ('paused
+ (set-fill-color! context "#ffffff")
+ (set-font! context "bold 24px monospace")
+ (set-text-align! context "center")
+ (fill-text context "PAUSED" (/ game-width 2.0) (/ game-height 2.0)))
(_ #t))
(request-animation-frame draw))
@@ -957,16 +968,30 @@
((string-=? code "KeyZ")
(set-firing! #t)
(prevent-default! event))
- ((string-=? code "KeyR")
- (reset!)
- (prevent-default! event)))
- (match *game-state*
- ('game-over
- (cond
- ((string-=? code "Enter")
- (reset!)
- (prevent-default! event))))
- (_ #t))))
+ (else
+ (match *game-state*
+ ('play
+ (cond
+ ((string-=? code "Enter")
+ (set! *game-state* 'paused)
+ (prevent-default! event))
+ ((string-=? code "KeyR")
+ (reset!)
+ (prevent-default! event))
+ ((string-=? code "KeyW")
+ (set! *game-state* 'game-win)
+ (prevent-default! event))))
+ ('paused
+ (cond
+ ((string-=? code "Enter")
+ (set! *game-state* 'play)
+ (prevent-default! event))))
+ ((or 'game-over 'game-win)
+ (cond
+ ((string-=? code "Enter")
+ (reset!)
+ (prevent-default! event))))
+ (_ #t))))))
(define (on-key-up event)
(let ((code (keyboard-event-code event)))