Commits

Christian Kellermann  committed 2ce8ca0

Add a muting

Pressing 'm' now mutes and unmutes sound

  • Participants
  • Parent commits 4f14cc7

Comments (0)

Files changed (1)

File beesteroids.scm

          (a (thing-heading ship))
          (r (thing-bounding-radius ship)))
     (when (< 0 bullets-left)
-          (play-sample *firing-sound* channel: 2 duration: 1000)
-      (world-bullets-left-set! world (sub1 bullets-left))
-      (world-bullets-set! world
-                          (cons (make-bullet (radial-point-from pos (+ r 10) a) a 2)
-                                (world-bullets world))))))
+          (unless *muted* (play-sample *firing-sound* channel: 2 duration: 1000))
+          (world-bullets-left-set! world (sub1 bullets-left))
+          (world-bullets-set! world
+                              (cons (make-bullet (radial-point-from pos (+ r 10) a) a 2)
+                                    (world-bullets world))))))
 
 ;; Start with a new world
 (define (new-world #!key (level 1) (score 0) (lives 3) ship)
          (a2 (list (- (first pos) r)
                    (second pos)))
          (new-r (- r 10)))
-    (play-sample *explosion-sound* channel: 3 duration: 3000)
+    (unless *muted* (play-sample *explosion-sound* channel: 3 duration: 3000))
     (if (> new-r 20)
         (world-asteroids-set!
          *w*
 (set! *rotating* #f)
 (set! *debugging* #f)
 (set! *paused* #f)
+(set! *muted* #f)
 
 ;; make us a global new world
 (world-inits
               (set! *debugging* #f))
              (('key 'released #\p)
               (set! *paused* (not *paused*)))
+             (('key 'pressed #\m)
+              (set! *muted* (not *muted*))
+              (if *muted*
+                  (halt-music *background-music*)
+                  (play-music *background-music*)))
 
              ;; Ship controls
              (('key 'pressed #\space)
    (let* ((s (world-ship *w*))
           (pos (thing-pos s))
           (shield (world-shield *w*)))
-     (cond ( *thrusting*
+     (cond (*thrusting*
              (thing-thrust-set! s (+ (thing-thrust s) (* 10 dt)))
-             (unless (channel-playing? 1)
+             (unless (and (not *muted*) (channel-playing? 1))
                (play-sample *thrust-sound* duration: 40 channel: 1)))
            (else
             (thing-thrust-set! s 0)))