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; }
public bool TryGetTerrainImage([NotNullWhen(true)] out IImage?image) { if (_terrainMap.IsEmpty()) { image = null; return(false); } if (_dirty == true || _terrainImage == null) { // Should we be getting this from here? int columns = _terrainMap.Max(x => x.Column); int rows = _terrainMap.Max(x => x.Row); // If we try to build before we know the size of the world, stay marked as dirty/null if (columns < 1 || rows < 1) { image = null; return(false); } _terrainImage = BuildTerrainImage(columns, rows); _dirty = false; } image = _terrainImage; return(true); }