Example #1
0
        private void OnPathChangedHandler()
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                ClearSprites();

                var drawing = new DrawingVisual();
                using (var context = drawing.RenderOpen())
                {
                    context.DrawEllipse(Brushes.YellowGreen, null,
                                        new Point(25, 25), 5, 5);
                }

                var source =
                    new RenderTargetBitmap(Constants.CellSize, Constants.CellSize, 96, 96, PixelFormats.Pbgra32);
                source.Render(drawing);

                foreach (var point in _ship.Path)
                {
                    var pathSprite = new DrawnObjectViewModel(source)
                    {
                        X = point.X * Constants.CellSize,
                        Y = point.Y * Constants.CellSize
                    };
                    _pathSprites.Add(pathSprite);
                    OnSpriteAdded?.Invoke(this, pathSprite);
                }
            });
        }
Example #2
0
 private void SpriteRemovedHandler(object sender, DrawnObjectViewModel e)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         _drawableObjects.Remove(e);
         OnPropertyChanged(nameof(DrawableObjects));
     });
 }
Example #3
0
        public void DrawMap(Map map)
        {
            var maxDepth = map.GetMaxDepth();

            for (var x = 0; x < map.Width; x++)
            {
                for (var y = 0; y < map.Height; y++)
                {
                    var cell = map.GetCell(new Point(x, y));

                    var drawing = new DrawingVisual();

                    SolidColorBrush brush;
                    if (cell.Depth > 0)
                    {
                        var depthCoefficient = cell.Depth / maxDepth;
                        var redValue         = 255 - 255 * depthCoefficient;
                        brush = new SolidColorBrush(Color.FromArgb(255, (byte)redValue, 255, 0));
                    }
                    else
                    {
                        brush = new SolidColorBrush(Color.FromArgb(64, 255, 0, 0));
                    }

                    using (var context = drawing.RenderOpen())
                    {
                        context.DrawRectangle(brush, new Pen(Brushes.Black, 2),
                                              new Rect(new GraphicsPoint(0, 0), new GraphicsPoint(Constants.CellSize, Constants.CellSize)));

                        var text = DrawingHelpers.GetFormattedText(cell.Depth.ToString(CultureInfo.CurrentCulture), 10, new SolidColorBrush(Colors.Black));
                        context.DrawText(text, new GraphicsPoint(10, 25));
                    }


                    var source = new RenderTargetBitmap(Constants.CellSize, Constants.CellSize, 96, 96, PixelFormats.Pbgra32);
                    source.Render(drawing);

                    var drawer = new DrawnObjectViewModel(source)
                    {
                        X = x * Constants.CellSize,
                        Y = y * Constants.CellSize
                    };
                    _drawableObjects.Add(drawer);
                }
            }
        }
Example #4
0
        public ShipDrawerViewModel(Ship ship)
        {
            _ship   = ship;
            Sprites = new ObservableCollection <DrawnObjectViewModel>();

            var source = GetImage();

            _shipSprite = new DrawnObjectViewModel(source)
            {
                X = _ship.CurrentPosition.X * Constants.CellSize,
                Y = _ship.CurrentPosition.Y * Constants.CellSize
            };
            _pathSprites = new List <DrawnObjectViewModel>();

            Sprites.Add(_shipSprite);
            _ship.OnMoved            += ShipMovedHandler;
            _ship.OnPathChanged      += OnPathChangedHandler;
            _ship.OnDirectionChanged += DirectionChangedHandler;
            _ship.OnDie += DieHandler;
        }
Example #5
0
 private void SpriteChangedHandler(object sender, DrawnObjectViewModel e)
 {
     throw new NotImplementedException();
 }