Пример #1
0
        public override void Draw(SKCanvas canvas, RectangleF dirtyRect)
        {
            if (dirtyRect.IsEmpty)
            {
                return;
            }
            if (!_redraw)
            {
                return;
            }

            const int maxGridSize = PixelMapper.MaxGridSize;

            using var bitmap = new SKBitmap(maxGridSize, maxGridSize, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            using var tempCanvas = new SKCanvas(bitmap);
            tempCanvas.Clear(TerrainColourLookup.DefaultColour.ToSkia());
            using var canvasWrapper = new SKCanvasWrapper(tempCanvas);

            using var paint = new SKPaint
                  {
                      Style = SKPaintStyle.Fill,
                  };

            foreach (Terrain terrain in _terrainMap)
            {
                paint.Color    = TerrainColourLookup.GetTerrainColour(terrain).ToSkia();
                (int x, int y) = _pixelMapper.CoordsToWorldPixels(terrain.Column, terrain.Row);
                tempCanvas.DrawRect(new SKRect(x, y, _gameParameters.CellSize + x, _gameParameters.CellSize + y), paint);
            }

            foreach (Track track in _trackLayout.OfType <Track>())
            {
                (int x, int y) = _pixelMapper.CoordsToWorldPixels(track.Column, track.Row);
                tempCanvas.DrawRect(new SKRect(x, y, _gameParameters.CellSize + x, _gameParameters.CellSize + y), _paint);
            }

            tempCanvas.DrawRect(new SKRect(_pixelMapper.ViewPortX * -1, _pixelMapper.ViewPortY * -1, Math.Abs(_pixelMapper.ViewPortX) + _pixelMapper.ViewPortWidth, Math.Abs(_pixelMapper.ViewPortY) + _pixelMapper.ViewPortHeight), _viewPortPaint);

            canvas.DrawBitmap(bitmap, new SKRect(0, 0, maxGridSize, maxGridSize), new SKRect(0, 0, 100, 100));

            _redraw = false;
        }
Пример #2
0
        public override void Draw(SKCanvas canvas, RectangleF dirtyRect)
        {
            if (dirtyRect.IsEmpty)
            {
                return;
            }
            if (!_redraw)
            {
                return;
            }

            canvas.Clear(TerrainColourLookup.DefaultColour.ToSkia());

            using var paint = new SKPaint
                  {
                      Style = SKPaintStyle.Fill,
                  };

            foreach (Terrain terrain in _terrainMap)
            {
                paint.Color = TerrainColourLookup.GetTerrainColour(terrain).ToSkia();
                canvas.DrawRect(terrain.Column, terrain.Row, 1, 1, paint);
            }

            foreach (Track track in _trackLayout.OfType <Track>())
            {
                canvas.DrawRect(track.Column, track.Row, 1, 1, _paint);
            }

            (int left, int top)     = _pixelMapper.ViewPortPixelsToCoords(0, 0);
            (int right, int bottom) = _pixelMapper.ViewPortPixelsToCoords(_pixelMapper.ViewPortWidth, _pixelMapper.ViewPortHeight);

            canvas.DrawRect(left, top, right - left, bottom - top, _viewPortPaint);

            _redraw = false;
        }
Пример #3
0
 public static bool IsWater(this Terrain terrain)
 => terrain.Height <= TerrainColourLookup.GetWaterLevel();