Permalink
Browse files

Allow sounds to overlap

  • Loading branch information...
1 parent af1f089 commit e2229204015166a40df6f4c73248a2d7693b9e8e Daniel Mark Schwartz committed Nov 30, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 game.coffee
View
@@ -397,10 +397,10 @@ fireEvery = (fireEvery=1) ->
die =
normal: (e) ->
- game.soundOn 'explosion0'
+ game.soundStart 'explosion0'
game.scene.spawnExplosion e.x, e.y
massive: (e) ->
- game.soundOn 'explosion1'
+ game.soundStart 'explosion1'
for i in [0 .. 15]
game.scene.spawnExplosion atom.width * randNorm() + e.x - atom.width/2, atom.height * randNorm() + e.y - atom.height/2
@@ -536,7 +536,7 @@ class Ship
@beamSpace = 6
collide: ->
- game.soundOn 'explosion0'
+ game.soundStart 'explosion0'
game.scene.spawnExplosion @x, @y
if not game.immune
game.scene.fadeOut 1, () -> game.sceneChange new Scene title
@@ -899,6 +899,12 @@ class Game extends atom.Game
musicPause: ->
@music?.pause()
+ soundStart: (sound, gain = 1) ->
+ a = new Audio
+ a.src = game.sounds[sound].src
+ game.sounds[sound].volume = gain
+ a.play()
+
soundOn: (sound, gain = 1) ->
game.sounds[sound].play()
game.sounds[sound].volume = gain

0 comments on commit e222920

Please sign in to comment.