Hello everyone!
I'm currently trying to implement this FOV algorithm (The Java one) (
www.roguebasin.com/index.php?title=FOV_using_recursive_shadowcasting_-_improved) into my roguelike but I'm having some trouble figuring out what the values are supposed to be.
Right now it's the actor who has these methods to determine what they can see and here's what I've got.
public void playerFOV_Recursive(){
for(int xd = -1; xd < 2; xd++){
for(int yd = -1; yd < 2; yd++){
if(yd != 0 && xd != 0){
castLight(1, 1.0f, 0.0f, 0, xd, yd, 0);
castLight(1, 1.0f, 0.0f, xd, 0, 0, yd);
}
}
}
for(int xv = 0; xv < 63; xv++){
for(int yv = 0; yv < 63; yv++){
if(lightMap[xv][yv] >= 1.0){
getCurrentLevel().getMapArray(xv,yv).visible = true;
}
}
}
}
public void castLight(int row, float start, float end, int xx, int xy, int yx, int yy){
float newStart = 0.0f;
float radius = 100;
if (start < end) {
return;
}
boolean blocked = false;
for (int distance = row; distance <= radius && !blocked; distance++) {
int deltaY = -distance;
for (int deltaX = -distance; deltaX <= 0; deltaX++) {
int currentX = getPosX() + deltaX * xx + deltaY * xy;
int currentY = getPosY() + deltaX * yx + deltaY * yy;
float leftSlope = (deltaX - 0.5f) / (deltaY + 0.5f);
float rightSlope = (deltaX + 0.5f) / (deltaY - 0.5f);
if (!(currentX >= 0 && currentY >= 0 && currentX < 63 && currentY < 63) || start < rightSlope) {
continue;
} else if (end > leftSlope) {
break;
}
//check if it's within the lightable area and light if needed
if ((deltaX + deltaY) <= radius) {
float bright = (float) (1 - ((deltaX + deltaY) / radius));
lightMap[currentX][currentY] = bright;
}
if (blocked) { //previous cell was a blocking one
if (lightMap[currentX][currentY] >= 1) {//hit a wall
newStart = rightSlope;
continue;
} else {
blocked = false;
start = newStart;
}
} else {
if (lightMap[currentX][currentY] >= 1 && distance < radius) {//hit a wall within sight line
blocked = true;
castLight(distance + 1, start, leftSlope, xx, xy, yx, yy);
newStart = rightSlope;
}
}
}
}
}
Right now it only lights the tiles next to the player.
Basically I'm not sure what startx,starty was supposed to be or if I adapted things incorrectly. Any help is much appreciated.