I'm currently working on a 2D top-down survival game and I'm trying to figure out a good method for enemies to detect player sounds. For instance - if the player fires his gun it should play a sound (already implemented) and then enemies near the player should 'hear' the sound and react to it.
The obvious solution is to simply check a radius around the sound origin for enemies and flag them as having heard the sound. The issue here is that I have many buildings and walls and other objects that would normally interfere with sound. If I simply do a radius check then enemies will hear the player through walls and bulkheads.
The next obvious solution is to use raycasting. I cast a ray to every enemy within a radius of the origin of the sound and if the ray hasn't hit anything then the enemy can hear the sound. This method works, but I'm looking for something more natural.
What I'm hoping for is a method of having sound rays penetrate walls and lose intensity depending on the object. I'm using Farseer Physics and am currently working towards this implementation but there's one catch that I haven't figured out. If an enemy is around a corner then the ray will pass through the wall and lower intensity even though the enemy SHOULD be able to hear the sound loud and clear. I know this has to do with sounds bouncing off of other walls and echoing but I have no idea how to implement that without raycasting like crazy.
My question then becomes: Does anyone have a semi-realistic method of producing a sound in a 2D world, and having enemies react to it through, and around walls?