Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example - Cells further away in FOV are dimmer
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();
}
}
@FaronBracy

This comment has been minimized.

Copy link
Owner Author

@FaronBracy FaronBracy commented Mar 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment