Created
March 2, 2019 13:59
-
-
Save FaronBracy/2ff15600ef59c4d3418488bee548f291 to your computer and use it in GitHub Desktop.
Example - Cells further away in FOV are dimmer
This file contains 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
public class Program | |
{ | |
private static double DistanceBetween( int x1, int y1, int x2, int y2 ) | |
{ | |
return Math.Sqrt( Math.Pow( x2 - x1, 2 ) + Math.Pow( y2 - y1, 2 ) ); | |
} | |
private static int WalkingDistanceBetween( int x1, int y1, int x2, int y2 ) | |
{ | |
return Math.Abs( x2 - x1 ) + Math.Abs( y2 - y1 ); | |
} | |
private static void OnRootConsoleRender( object sender, UpdateEventArgs e ) | |
{ | |
_map.ComputeFov( _partyX, _partyY, 50, true ); | |
foreach ( var cell in _map.GetAllCells() ) | |
{ | |
if ( cell.IsInFov ) | |
{ | |
int distance = WalkingDistanceBetween( _partyX, _partyY, cell.X, cell.Y ); | |
int blendValue = 256 - distance * 20; | |
byte blendAmount = blendValue > 20 ? (byte) blendValue : (byte) 20; | |
RLColor color = new RLColor( blendAmount, blendAmount, blendAmount ); | |
_map.SetCellProperties( cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true ); | |
if ( cell.IsWalkable ) | |
{ | |
_mapConsole.Set( cell.X, cell.Y, color, null, 16 * 8 ); | |
} | |
else | |
{ | |
if ( cell.Y + 1 < _mapHeight && !_map.GetCell( cell.X, cell.Y + 1 ).IsWalkable ) | |
{ | |
_mapConsole.Set( cell.X, cell.Y, color, null, 16 * 11 + 257 ); | |
} | |
else | |
{ | |
_mapConsole.Set( cell.X, cell.Y, color, null, '#' + 256 ); | |
} | |
} | |
} | |
else if ( cell.IsExplored ) | |
{ | |
if ( cell.IsWalkable ) | |
{ | |
_mapConsole.Set( cell.X, cell.Y, new RLColor( 30, 30, 30 ), null, '.' ); | |
} | |
else | |
{ | |
if ( cell.Y + 1 < _mapHeight && !_map.GetCell( cell.X, cell.Y + 1 ).IsWalkable ) | |
{ | |
_mapConsole.Set( cell.X, cell.Y, RLColor.Gray, null, 16 * 11 + 257 ); | |
} | |
else | |
{ | |
_mapConsole.Set( cell.X, cell.Y, RLColor.Gray, null, '#' + 256 ); | |
} | |
} | |
} | |
} | |
RLConsole.Blit( _mapConsole, 0, 0, _mapWidth, _mapHeight, _rootConsole, 1, 1 ); | |
_rootConsole.Draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.screencast.com/t/IThIy3QVZ