Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Woog

Pages: [1]
1
Programming / Re: Shadowcast Java algorithm
« on: March 27, 2015, 04:48:06 AM »
Wow didn't expect such heated debate about FOV algorithms.

Anyway I am just using something like this now.

http://i.imgur.com/3HuRUn0.png

It works and is symmetrical, although I'm not sure how fast it is. At least straight lines are easy to figure out. I'll try some of these suggestions and see how it works.

2
Programming / Re: Shadowcast Java algorithm
« on: November 13, 2014, 09:26:31 PM »
Update: I've got it mostly working but I still have a problem with corners like this

@ = player
. = floor
# = wall
S = Shadow

.@.
##.
##.
##S


The player can't see 'S' but 'S' can see the player

3
Programming / Shadowcast Java algorithm
« on: November 13, 2014, 05:10:32 PM »
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.

Code: [Select]
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.

Pages: [1]