From cd55667a8c86f3f393d71ade31c3b7ba6166e359 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Fri, 13 Jun 2014 23:12:35 -0700 Subject: [PATCH] Add positional sounds from the tilemap --- moonlight/js/moonlight-skulk.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/moonlight/js/moonlight-skulk.js b/moonlight/js/moonlight-skulk.js index fcbfbbf..414ef12 100644 --- a/moonlight/js/moonlight-skulk.js +++ b/moonlight/js/moonlight-skulk.js @@ -114,25 +114,21 @@ SoundSprite.prototype.adjust_relative_to = function(spr) { // The volume of any given sound is equal to the length of the // hypotenuse of a triangle drawn from the point (p) to the - // nearest corner of the camera + // sprite in question - var xd_right = (game.camera.x + game.camera.width - this.x); - var xd_left = this.x - game.camera.x; - var yd_bottom = (game.camera.y + game.camera.height - this.y); - var yd_top = this.y - game.camera.y; + 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)) ); - var hyp_right = Math.sqrt((xd_right * xd_right) + (yd_bottom * yd_bottom)); - var hyp_left = Math.sqrt((xd_left * xd_left) + (yd_top * yd_top)); - - if ( hyp_right > hyp_left ) { - this.sound.volume = Number(hyp_perfect / hyp_left); - } else { - this.sound.volume = Number(hyp_perfect / hyp_right); - } - console.log([hyp_perfect, hyp_left, hyp_right, this.sound.volume]); + this.sound.volume = Number(hyp_perfect / hyp); + console.log([hyp_perfect, hyp, this.sound.volume]); } var moonlightSettings = {