Allow the same sound effect to be played many times simultaneously.
This commit is contained in:
parent
e09efb46a0
commit
bcb235bd82
2 changed files with 50 additions and 11 deletions
21
game.scm
21
game.scm
|
@ -26,6 +26,7 @@
|
|||
(dom media)
|
||||
(dom window)
|
||||
(game actors)
|
||||
(game audio)
|
||||
(game level)
|
||||
(game levels level-1)
|
||||
(game levels level-2)
|
||||
|
@ -58,9 +59,7 @@
|
|||
(inexact->exact tile-width)
|
||||
(inexact->exact tile-height)))
|
||||
(define* (load-sound-effect name #:key (volume 0.25))
|
||||
(let ((audio (make-audio (string-append "assets/sounds/" name ".wav"))))
|
||||
(set-media-volume! audio volume)
|
||||
audio))
|
||||
(make-sound-effect (string-append "assets/sounds/" name ".wav")))
|
||||
(define audio:bump (load-sound-effect "bump"))
|
||||
(define audio:push (load-sound-effect "push"))
|
||||
(define audio:undo (load-sound-effect "undo"))
|
||||
|
@ -97,11 +96,11 @@
|
|||
(set! *snapshots* (cons (copy-whactormap *actormap*) *snapshots*)))
|
||||
(define (rollback-snapshot!)
|
||||
(match *snapshots*
|
||||
(() (media-play audio:no))
|
||||
(() (play-sound-effect audio:no))
|
||||
((snapshot . older-snapshots)
|
||||
(set! *actormap* snapshot)
|
||||
(set! *snapshots* older-snapshots)
|
||||
(media-play audio:undo))))
|
||||
(play-sound-effect audio:undo))))
|
||||
|
||||
(define (sort lst compare)
|
||||
(match lst
|
||||
|
@ -210,19 +209,19 @@
|
|||
(let ((result
|
||||
(match ($ player 'event)
|
||||
(('bump)
|
||||
(media-play audio:bump)
|
||||
(play-sound-effect audio:bump)
|
||||
#f)
|
||||
(('push)
|
||||
(media-play audio:push)
|
||||
(play-sound-effect audio:push)
|
||||
#f)
|
||||
(('exit)
|
||||
(media-play audio:exit)
|
||||
(play-sound-effect audio:exit)
|
||||
'next-level)
|
||||
(('die)
|
||||
(media-play audio:die)
|
||||
(play-sound-effect audio:die)
|
||||
#f)
|
||||
(('gem)
|
||||
(media-play audio:pickup)
|
||||
(play-sound-effect audio:pickup)
|
||||
;; TODO: Maybe show a little achievement popup when all gems
|
||||
;; are collected?
|
||||
(set! *gems* (cons *level-idx* *gems*))
|
||||
|
@ -232,7 +231,7 @@
|
|||
(save-snapshot!)
|
||||
result))
|
||||
(begin
|
||||
(media-play audio:no)
|
||||
(play-sound-effect audio:no)
|
||||
#f)))))
|
||||
(when (eq? (do-move) 'next-level)
|
||||
(next-level!)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue