Created
February 13, 2013 02:35
-
-
Save anonymous/4909278 to your computer and use it in GitHub Desktop.
Line of sight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (int x0 = playerXPos-MAPSIZE*2; x0 <= playerXPos+MAPSIZE*2; x0++){ | |
for (int y0 = playerYPos-MAPSIZE*2; y0 <= playerYPos+MAPSIZE*2; y0++){ | |
int dx = abs(x0 - playerXPos); | |
int dy = abs(y0 - playerYPos); | |
int x = playerXPos; | |
int y = playerYPos; | |
int n = 1 + dx + dy; | |
int x_inc = (x0 > playerXPos) ? 1 : -1; | |
int y_inc = (y0 > playerYPos) ? 1 : -1; | |
int error = dx - dy; | |
dx *= 2; | |
dy *= 2; | |
for (; n > 0; n--){ | |
if (error > 0){ | |
x += x_inc; | |
error -= dy; | |
if (tiles[y][x].wallsGFX ==0){ | |
tiles[x][y].rays = 1; | |
} | |
else if (tiles[y][x].wallsGFX !=0){ | |
break; | |
} | |
} | |
else{ | |
y += y_inc; | |
error += dx; | |
if (tiles[y][x].wallsGFX ==0){ | |
tiles[x][y].rays = 1; | |
} | |
else if (tiles[y][x].wallsGFX !=0) | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment