public void Render(ICanvas canvas, int width, int height, IPixelMapper pixelMapper) { if (_terrainMap.IsEmpty()) { canvas.DrawRect(0, 0, pixelMapper.ViewPortWidth, pixelMapper.ViewPortHeight, new PaintBrush { Style = PaintStyle.Fill, Color = TerrainColourLookup.DefaultColour }); return; } // Draw any non-grass cells foreach (Terrain terrain in _terrainMap) { Color colour = TerrainColourLookup.GetTerrainColour(terrain); (int x, int y) = pixelMapper.CoordsToViewPortPixels(terrain.Column, terrain.Row); canvas.DrawRect(x, y, _gameParameters.CellSize, _gameParameters.CellSize, new PaintBrush { Style = PaintStyle.Fill, Color = colour }); // Debug, this draws coord and height onto cells //canvas.DrawText($"{terrain.Column},{terrain.Row}", x + 2, y + 0.3f * _gameParameters.CellSize, new PaintBrush { Style = PaintStyle.Fill, Color = Colors.Black }); //canvas.DrawText($"{terrain.Height}", x + 2, y + 0.7f * _gameParameters.CellSize, new PaintBrush { Style = PaintStyle.Fill, Color = Colors.Black }); } _dirty = false; }
public void Render(ICanvas canvas, int width, int height, IPixelMapper pixelMapper) { canvas.DrawRect(0, 0, pixelMapper.ViewPortWidth, pixelMapper.ViewPortHeight, new PaintBrush { Style = PaintStyle.Fill, Color = TerrainColourLookup.DefaultColour }); if (_terrainMap.IsEmpty()) { return; } // Draw any non-grass cells foreach (Terrain terrain in _terrainMap) { (int x, int y, bool onScreen) = pixelMapper.CoordsToViewPortPixels(terrain.Column, terrain.Row); if (!onScreen) { continue; } Color colour = TerrainColourLookup.GetTerrainColour(terrain); if (colour == TerrainColourLookup.DefaultColour) { continue; } canvas.DrawRect(x, y, pixelMapper.CellSize, pixelMapper.CellSize, new PaintBrush { Style = PaintStyle.Fill, Color = colour }); } _dirty = false; }
private IImage BuildTerrainImage(int columns, int rows) { using IImageCanvas textureImage = _imageFactory.CreateImageCanvas(columns, rows); textureImage.Canvas.DrawRect(0, 0, columns, rows, new PaintBrush { Style = PaintStyle.Fill, Color = TerrainColourLookup.DefaultColour }); foreach (Terrain terrain in _terrainMap) { Color colour = TerrainColourLookup.GetTerrainColour(terrain); if (colour == TerrainColourLookup.DefaultColour) { continue; } textureImage.Canvas.DrawRect(terrain.Column, terrain.Row, 1, 1, new PaintBrush { Style = PaintStyle.Fill, Color = colour }); } return(textureImage.Render()); }
public bool IsValid(int column, int row) => _entityCollection.IsAvailable(column, row) && _terrainMap.GetTerrainOrDefault(column, row).Height > TerrainColourLookup.GetWaterLevel();