I actually got it to work by only changing only a few lines of code:
Before/after screenshot:
http://i.imgur.com/biqbG.pngToward the bottom of the update() method, where line of sight obstructions are checked:
Code:
int div = 1;
// Check objects, could use optimization, should not need to check them all?
for (Rectangle r : obstructions)
{
if (lineOfSightLine.intersects(r))
{
div++; //Add one to "div" for each obstruction that is blocking this tile
}
}
float[] effect;
for (int component = 0; component < 3; component++)
{
// check effect on each corner
// Divide the effect by "div" to make the tile darker
// top left
effect = light.getEffectAtCorner(new Vector2f(x * tileSize, y * tileSize), colouredLights);
lightValue[x][y][0][component] += effect[component]/div;
// top right
effect = light.getEffectAtCorner(new Vector2f(x * tileSize + tileSize, y * tileSize), colouredLights);
lightValue[x][y][1][component] += effect[component]/div;
// bottom left
effect = light.getEffectAtCorner(new Vector2f(x * tileSize, y * tileSize + tileSize), colouredLights);
lightValue[x][y][2][component] += effect[component]/div;
// bottom right
effect = light.getEffectAtCorner(new Vector2f(x * tileSize + tileSize, y * tileSize + tileSize), colouredLights);
lightValue[x][y][3][component] += effect[component]/div;
}
It's probably a slow, inefficient way to do it, but it does give the desired effect (for the most part). It needs optimization, using larger TiledMaps murders the frame rate. The update() method takes the longest, but the render() method gets slower as more tiles are added. Any ideas on how to speed this up? I can post the full source code if necessary, but its mostly the same as the example code that liamzebedee posted earlier.