public static void updateLight(int x, int y)
{
byte myLight = getLight(x, y);
if (getWall(x, y) == null) //Checks if there's a wall behind, if not it sets the light at this position to the max light and updates spaces next to this space.
{
byte lightPower = 6;
setLight(x, y, lightPower);
if (getLight(x - 1, y) < lightPower-1)
{
setLight(x - 1, y, (byte)(lightPower-1));
if (getWall(x - 1, y) != null)
updateLight(x - 1, y);
}
if (getLight(x + 1, y) < lightPower-1)
{
setLight(x + 1, y, (byte)(lightPower-1));
if (getWall(x + 1, y) != null)
updateLight(x + 1, y);
}
if (getLight(x, y - 1) < lightPower-1)
{
setLight(x, y - 1, (byte)(lightPower-1));
if (getWall(x, y - 1) != null)
updateLight(x, y - 1);
}
if (getLight(x, y + 1) < lightPower-1)
{
setLight(x, y + 1, (byte)(lightPower-1));
if (getWall(x, y + 1) != null)
updateLight(x, y + 1);
}
}
else
{
if (myLight > 12) // If there's a wall behind it shouldn't be able to have the max light.
{
setLight(x, y, (byte) 12);
}
if (myLight > 0) //If the own light is greater than 0 it checks if the spaces next to it are less lit then this space - 1. If so, it changes the light to the own light -1 and updates it.
{
byte light = getLight(x, y);
if (getLight(x - 1, y) < light - 1)
{
setLight(x - 1, y, (byte) (light - 1));
if (getWall(x - 1, y) != null)
updateLight(x - 1, y);
}
if (getLight(x + 1, y) < light - 1)
{
setLight(x + 1, y, (byte) (light - 1));
if (getWall(x + 1, y) != null)
updateLight(x + 1, y);
}
if (getLight(x, y - 1) < light - 1)
{
setLight(x, y - 1, (byte) (light - 1));
if (getWall(x, y - 1) != null)
updateLight(x, y - 1);
}
if (getLight(x, y + 1) < light - 1)
{
setLight(x, y + 1, (byte) (light - 1));
if (getWall(x, y + 1) != null)
updateLight(x, y + 1);
}
}
}
}