Add positional sounds from the tilemap

This commit is contained in:
2014-06-13 23:19:20 -07:00
parent 4505486bf7
commit c96610c899

View File

@@ -90,6 +90,32 @@ SoundSprite.prototype = Object.create(Phaser.Sprite.prototype);
SoundSprite.prototype.constructor = Light;
SoundSprite.prototype.update_new_values = function() {
this.adjust_relative_to = function(spr) {
console.log(spr);
if ( this.sound_nofade == true ) {
this.sound.volume = 1.0;
return;
}
// The volume of any given sound is equal to the length of the
// hypotenuse of a triangle drawn from the point (p) to the
// sprite in question
var xd = (spr.x - this.x);
if ( xd < 0 )
xd = -(xd);
var yd = (spr.y - this.y);
if ( yd < 0 )
yd = -(yd);
var hyp = Math.sqrt((xd * xd) + (yd * yd));
var hyp_perfect = Math.sqrt(
((game.camera.width/2) * (game.camera.width/2)) +
((game.camera.height/2) * (game.camera.height/2))
);
this.sound.volume = Number(hyp_perfect / hyp);
console.log([hyp_perfect, hyp, this.sound.volume]);
}
if ( this.sound_key == null ) {
if ( this.sound !== null ) {
this.sound.stop();
@@ -106,32 +132,6 @@ SoundSprite.prototype.update_new_values = function() {
console.log("Sound should be playing");
}
SoundSprite.prototype.adjust_relative_to = function(spr) {
console.log(spr);
if ( this.sound_nofade == true ) {
this.sound.volume = 1.0;
return;
}
// The volume of any given sound is equal to the length of the
// hypotenuse of a triangle drawn from the point (p) to the
// sprite in question
var xd = (spr.x - this.x);
if ( xd < 0 )
xd = -(xd);
var yd = (spr.y - this.y);
if ( yd < 0 )
yd = -(yd);
var hyp = Math.sqrt((xd * xd) + (yd * yd));
var hyp_perfect = Math.sqrt(
((game.camera.width/2) * (game.camera.width/2)) +
((game.camera.height/2) * (game.camera.height/2))
);
this.sound.volume = Number(hyp_perfect / hyp);
console.log([hyp_perfect, hyp, this.sound.volume]);
}
var moonlightSettings = {
'map' : {
'tilesets': [
@@ -1078,6 +1078,7 @@ GameState.prototype.update = function()
}
function _fix_audio_relative(x) {
console.log(x);
x.adjust_relative_to(this.player);
}
this.staticSounds.forEach(_fix_audio_relative, this);