summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.scm38
1 files changed, 37 insertions, 1 deletions
diff --git a/game.scm b/game.scm
index 2f18584..8200f3d 100644
--- a/game.scm
+++ b/game.scm
@@ -281,6 +281,14 @@
(vector-set! scheduler 0 t)
(vector-set! scheduler 1 k)
to-run))))))))
+ (define (scheduler-reset! scheduler)
+ (match scheduler
+ (#(ticks num-tasks max-tasks tasks)
+ (vector-set! scheduler 0 0)
+ (vector-set! scheduler 1 0)
+ (do ((i 0 (+ i 1)))
+ ((= i num-tasks))
+ (vector-set! tasks i #f)))))
(define *scheduler* (make-scheduler 100))
(define %script-tag (make-prompt-tag "script"))
(define (run-script thunk)
@@ -333,6 +341,10 @@
(start (bullet-pool-offset (- length 1))))
(bytevector-copy! bullets at bullets start (+ start %bullet-size))
(vector-set! pool 0 (- length 1)))))))
+ (define (bullet-pool-reset! pool)
+ (match pool
+ (#(length capacity bullets)
+ (vector-set! pool 0 0))))
(define (bullet-pool-update! pool collide)
(match pool
(#(length capacity bullets)
@@ -578,6 +590,15 @@
(let ((offset (enemy-pool-offset i)))
(f64-set! enemies (+ offset 40) dx)
(f64-set! enemies (+ offset 48) dy)))))
+ (define (enemy-pool-reset! pool)
+ (match pool
+ (#(length capacity enemies scripts)
+ (do ((i 0 (+ i 1)))
+ ((= i length))
+ (let ((script (vector-ref scripts i)))
+ (and script (cancel! script))
+ (vector-set! scripts i #f)))
+ (vector-set! pool 0 0))))
(define (enemy-pool-update! pool collide)
(match pool
(#(length capacity enemies scripts)
@@ -798,6 +819,19 @@
(draw-enemy-bullets)
(request-animation-frame draw))
+ (define (reset!)
+ (scheduler-reset! *scheduler*)
+ (set! *scroll* 0.0)
+ (bullet-pool-reset! player-bullets)
+ (bullet-pool-reset! enemy-bullets)
+ (enemy-pool-reset! enemies)
+ (set-vec2-x! player-position (/ game-width 2.0))
+ (set-vec2-y! player-position (- game-height 12.0))
+ (set! *player-lives* %default-lives)
+ (set! *player-invincible?* #f)
+ (set! *player-visible?* #t)
+ (set! *player-fire-counter* 0))
+
(define (on-key-down event)
(let ((code (keyboard-event-code event)))
(cond
@@ -810,7 +844,9 @@
((string-=? code "ArrowUp")
(set-up! #t))
((string-=? code "KeyZ")
- (set-firing! #t)))))
+ (set-firing! #t))
+ ((string-=? code "KeyR")
+ (reset!)))))
(define (on-key-up event)
(let ((code (keyboard-event-code event)))