Hi.
I’m rather new to java programming and i’m trying to learn by doing and seeing examples.
And i’m currently trying to writa a game which use a tilemap.
And i need it to be dark and some light sources.
This i have and it is working fine.
But now to the tricky problem, how can i get the “enemies” to be in the shadows (not visible) until it comes to a light source?
The solution i have now draws the enemy, the redraws the map ontop of the enemy so that the floor i sabove the enemy, and i dont se them.
here is my code:
for(int i=0;i<enemyCount;i++){
enemies[i].render(container, g);
}
//LIGHTS
for (int y = 0; y < map.tiledMap.getHeight(); y++) {
for (int x = 0; x < map.tiledMap.getWidth(); x++) {
Image image = map.tiledMap.getTileImage(x, y, map.tiledMap.getLayerIndex("WALL"));
if (image == null) {
image = map.tiledMap.getTileImage(x, y, map.tiledMap.getLayerIndex("FLOOR"));
}
image.setColor(Image.TOP_LEFT, lightValue[x][y][0], lightValue[x][y][1], lightValue[x][y][2], 1);
image.setColor(Image.TOP_RIGHT, lightValue[x+1][y][0], lightValue[x+1][y][1], lightValue[x+1][y][2], 1);
image.setColor(Image.BOTTOM_RIGHT, lightValue[x+1][y+1][0], lightValue[x+1][y+1][1], lightValue[x+1][y+1][2], 1);
image.setColor(Image.BOTTOM_LEFT, lightValue[x][y+1][0], lightValue[x][y+1][1], lightValue[x][y+1][2], 1);
image.draw(x*16, y*16);
}
}