private List <List <Vector2> > CastVisionRaysToEdges(ref GameTile visionOriginTile, ref Board map) { /* * Cast lines to all the edges of the given map using Bresenham's Line algorithm to create the initial visibility for an entity */ List <Vector2> result = new List <Vector2>(); List <List <Vector2> > results = new List <List <Vector2> >(); //cast lines to all the vertical edges of the map for (int x = 0; x < map.GetCols(); x++) { result = BresenhamLine(visionOriginTile.GetPosition(), map.GetGrid()[x][0].GetPosition()); results.Add(result); result = BresenhamLine(visionOriginTile.GetPosition(), map.GetGrid()[x][(map.GetRows() - 1)].GetPosition()); results.Add(result); } //cast lines to all the horizontal edges of the map for (int y = 0; y < map.GetRows(); y++) { result = BresenhamLine(visionOriginTile.GetPosition(), map.GetGrid()[0][y].GetPosition()); results.Add(result); result = BresenhamLine(visionOriginTile.GetPosition(), map.GetGrid()[(map.GetCols() - 1)][y].GetPosition()); results.Add(result); } return(results); }
// //privates private void ApplyTileFixesBySection(ref GameTile playerTile, ref List <GameTile> visibleTiles) { //TODO:Cleanup /* * Looks at all current visible floor tiles and applys fixes to the player's vision dependent on which "area" the tiles are around the player */ for (int x = 0; x < visibleTiles.Count; x++) { bool hasNorthWallTile = (visibleTiles[x].GetTileNorth() != null && visibleTiles[x].GetTileNorth().GetObject() != null && visibleTiles[x].GetTileNorth().IsWall()); bool hasSouthWallTile = (visibleTiles[x].GetTileSouth() != null && visibleTiles[x].GetTileSouth().GetObject() != null && visibleTiles[x].GetTileSouth().IsWall()); bool hasEastWallTile = (visibleTiles[x].GetTileEast() != null && visibleTiles[x].GetTileEast().GetObject() != null && visibleTiles[x].GetTileEast().IsWall()); bool hasWestWallTile = (visibleTiles[x].GetTileWest() != null && visibleTiles[x].GetTileWest().GetObject() != null && visibleTiles[x].GetTileWest().IsWall()); GameTile northWallTile = (hasNorthWallTile) ? visibleTiles[x].GetTileNorth() : null; GameTile southWallTile = (hasSouthWallTile) ? visibleTiles[x].GetTileSouth() : null; GameTile eastWallTile = (hasEastWallTile) ? visibleTiles[x].GetTileEast() : null; GameTile westWallTile = (hasWestWallTile) ? visibleTiles[x].GetTileWest() : null; if (visibleTiles[x].GetPosition().y == playerTile.GetPosition().y || visibleTiles[x].GetPosition().x == playerTile.GetPosition().x) { //these tiles lie directly on the same vertical or horizontal line the player is currently on if (visibleTiles[x].GetPosition().y == playerTile.GetPosition().y) { //on same horizontal line as the player if (visibleTiles[x].GetPosition().x > playerTile.GetPosition().x) { //TODO: if we are keeping this where it applies the same effect then remove the two inner if statements for both the horizontal and vertical, and then merge horizontal and vertical into one if check as well //on same horizontal line but to the east of the player, any visible floor tile in this section should illuminate any wall tiles in cardnial directions if (hasNorthWallTile) { northWallTile.SetIsVisible(true); } if (hasWestWallTile) { westWallTile.SetIsVisible(true); } if (hasSouthWallTile) { southWallTile.SetIsVisible(true); } if (hasEastWallTile) { eastWallTile.SetIsVisible(true); } } else if (visibleTiles[x].GetPosition().x < playerTile.GetPosition().x) { //on same horizontal line as the player but to the west of the player, any visible floor tile in this section should illuminate any wall tiles in cardnial directions if (hasNorthWallTile) { northWallTile.SetIsVisible(true); } if (hasEastWallTile) { eastWallTile.SetIsVisible(true); } if (hasSouthWallTile) { southWallTile.SetIsVisible(true); } if (hasWestWallTile) { westWallTile.SetIsVisible(true); } } } else { //on same vertical line as the player if (visibleTiles[x].GetPosition().y > playerTile.GetPosition().y) { //on same vertical line as the player but north of the player, any visible floor tile in this section should illuminate any wall tiles in cardnial directions if (hasSouthWallTile) { southWallTile.SetIsVisible(true); } if (hasWestWallTile) { westWallTile.SetIsVisible(true); } if (hasEastWallTile) { eastWallTile.SetIsVisible(true); } if (hasNorthWallTile) { northWallTile.SetIsVisible(true); } } else if (visibleTiles[x].GetPosition().y < playerTile.GetPosition().y) { //on same vertical line as the player but south of the player, any visible floor tile in this section should illuminate any wall tiles in cardnial directions if (hasNorthWallTile) { northWallTile.SetIsVisible(true); } if (hasWestWallTile) { westWallTile.SetIsVisible(true); } if (hasEastWallTile) { eastWallTile.SetIsVisible(true); } if (hasSouthWallTile) { southWallTile.SetIsVisible(true); } } } } else { //these tiles do not like directly on the same vertical or horizontal line as the player if (visibleTiles[x].GetPosition().y > playerTile.GetPosition().y) { //North sections if (visibleTiles[x].GetPosition().x > playerTile.GetPosition().x) { //north east //above the player's horizontal line and to the east of the player;s vertical line, any visible floor tile in this section should illuminate any wall tiles to the north or east if (hasNorthWallTile) { northWallTile.SetIsVisible(true); } if (hasEastWallTile) { eastWallTile.SetIsVisible(true); } } else { //north west //above the player's horizontal line and to the west of the player's vertical line, any visible floor tile in this section should illuminate any wall tiles to the north or west if (hasNorthWallTile) { northWallTile.SetIsVisible(true); } if (hasWestWallTile) { westWallTile.SetIsVisible(true); } } } else { if (visibleTiles[x].GetPosition().x > playerTile.GetPosition().x) { //south east //below the player's horizontal line and to the east of the player's vertical line, any visible floor tile in this section sould illuminate any wall tiles to the south or east if (hasSouthWallTile) { southWallTile.SetIsVisible(true); } if (hasEastWallTile) { eastWallTile.SetIsVisible(true); } } else { //south west //below the player's horizontal line and to the west of the player's vertical line, any visible floor tile in this section should illuminate any wall tiles to the south or west if (hasSouthWallTile) { southWallTile.SetIsVisible(true); } if (hasWestWallTile) { westWallTile.SetIsVisible(true); } } } } } }