Hey many thanks.
Yeah my physics isn’t great, only did it at high school level…
Here is what I got with placing a torch with max light value of 15:
And after placing a light pretty much next to this I get this ugly light scene:
As you can see, I’m not adding the light sources together.
My code:
static final int MAXLIGHTLEVEL = 15;
static final int W = 20;
static final int H = 15;
private static void setLightSource(int x, int y, BlankEntity[][] map, int lightLevel) {
map[x][y].lightValue = lightLevel;
updateTileLight(map, x, y);
}
private static void updateTileLight(BlankEntity[][] map, int lightX, int lightY) {
int lightLevel = 0;
for(int x = 0; x<1+W/2; x++)
{
for (int y = 0; y < (H / 2); y++) {
lightLevel = MAXLIGHTLEVEL - x - y;
if(lightLevel>15) lightLevel = MAXLIGHTLEVEL;
if(lightLevel<0) lightLevel = 0;
map[x+lightX][lightY - y].lightValue = lightLevel;
map[x+lightX][lightY + 1 + y].lightValue = lightLevel;
}
}
for(int x = 0; x<1+W/2; x++)
{
for (int y = 0; y < (H / 2); y++) {
lightLevel = MAXLIGHTLEVEL - x - y;
if(lightLevel>15) lightLevel = MAXLIGHTLEVEL;
if(lightLevel<0) lightLevel = 0;
map[lightX-x][lightY - y].lightValue = lightLevel;
map[lightX-x][lightY + 1 + y].lightValue = lightLevel;
}
}
}
The above code gets called when a light is placed. BlankEntity is a tile block, each have their own light level, thus when they are rendered I just do:
BlankEntity entity = getEntity(col, row);
float r = 1 * (float) entity.lightValue / MAXLIGHT;
float g = 1 * (float) entity.lightValue / MAXLIGHT;
float b = 1 * (float) entity.lightValue / MAXLIGHT;
batch.setColor(r, g, b, 1);
What would be the best way of working light values out if a few torches are placed say next to each other? Do I need to check for torches being near each other?
PS - the light that kinda shines from the player and looks like a torch is just a box2d light.
Many thanks again