From db22f4655bfc3dced71b495293f4bab1f6c31ad9 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 3 Jun 2012 08:47:17 -0400 Subject: Added field of view (using recursive shadowcasting) --- .../fourisland/frigidearth/MapViewGameState.java | 109 ++++++++++++++++++--- 1 file changed, 98 insertions(+), 11 deletions(-) (limited to 'src/com/fourisland') diff --git a/src/com/fourisland/frigidearth/MapViewGameState.java b/src/com/fourisland/frigidearth/MapViewGameState.java index fe32fe2..aa489da 100644 --- a/src/com/fourisland/frigidearth/MapViewGameState.java +++ b/src/com/fourisland/frigidearth/MapViewGameState.java @@ -26,7 +26,9 @@ public class MapViewGameState implements GameState private final int MIN_ROOM_HEIGHT = 7; private final int MAX_CORRIDOR_LENGTH = 6; private final int MIN_CORRIDOR_LENGTH = 2; + private final int[][] OCTET_MULTIPLIERS = new int[][] {new int[] {1,0,0,-1,-1,0,0,1}, new int[] {0,1,-1,0,0,-1,1,0}, new int[] {0,1,1,0,0,-1,-1,0}, new int[] {1,0,0,1,-1,0,0,-1}}; private Tile[][] grid; + private boolean[][] gridLighting; private int playerx = 4; private int playery = 4; private int viewportx = 0; @@ -35,6 +37,7 @@ public class MapViewGameState implements GameState public MapViewGameState() { grid = new Tile[GAME_WIDTH][GAME_HEIGHT]; + gridLighting = new boolean[GAME_WIDTH][GAME_HEIGHT]; for (int x=0; x l_slope) + { + break; + } else { + if ((dx*dx + dy*dy) < r2) + { + gridLighting[x][y] = true; + } + + if (blocked) + { + if (grid[x][y].isBlocked()) + { + newStart = r_slope; + continue; + } else { + blocked = false; + start = newStart; + } + } else { + if ((grid[x][y].isBlocked()) && (j < radius)) + { + blocked = true; + castLight(cx, cy, j+1, start, l_slope, radius, xx, xy, yx, yy, id+1); + newStart = r_slope; + } + } + } + } + + if (blocked) + { + break; + } + } + } public void render(Graphics2D g) { @@ -484,18 +567,21 @@ public class MapViewGameState implements GameState { for (int y=viewporty; y