summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/engine/scenery/sound.js
blob: 2f7f8de53036510a1b681cf6b2f3cae06e7e03d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Scenery.sound = {}
Scenery.sound.max_distance = 600
Scenery.sound.init = function(){
  app.tube.on("move", Scenery.sound.move)
}
Scenery.sound.move = function(){
  var vals = Scenery.map(function(scenery){
    if ((scenery.type == "video" || scenery.type == "audio") && ! scenery.muted()) {
      //get distance from A to B
      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)
    }
  })
}