summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/scenery/sound.js
blob: 5a783d68f2e20b5e9d89c93094ebfe7b518e2884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Scenery.sound = {}
Scenery.sound.max_distance = 1500
Scenery.sound.init = function(){
  app.tube.on("move", Scenery.sound.move)
}
Scenery.sound.move = function(){
  Scenery.forEach(function(scenery){
    if ((scenery.type == "video" || scenery.type == "audio")) { // && ! scenery.muted()) {
      var distance = dist(cam.x, cam.z, 
                          scenery.mx.x, scenery.mx.z)
      var volume = 1 - (clamp( distance, 0, Scenery.sound.max_distance ) / Scenery.sound.max_distance)
      scenery.setVolume(volume)
    }
  })
}