Example #1
0
        protected MovingBodyViewModel(MovingBody m)
        {
            _m = m;

            VelocityVector = new Line
            {
                Stroke          = Brushes.Green,
                StrokeThickness = 1
            };

            AccelerationVector = new Line
            {
                Stroke          = Brushes.Red,
                StrokeThickness = 1
            };

            Name = new TextBlock
            {
                Text       = m.Name,
                Foreground = Brushes.White
            };

            SelectionCircle = new Ellipse
            {
                Width      = SelectionCircleSize,
                Height     = SelectionCircleSize,
                Stroke     = Brushes.Transparent,
                Fill       = Brushes.Transparent,
                Visibility = Visibility.Visible
            };

            SelectionCircle.MouseEnter          += (sender, args) => SelectionCircle.Stroke = Brushes.White;
            SelectionCircle.MouseLeave          += (sender, args) => SelectionCircle.Stroke = Brushes.Transparent;
            SelectionCircle.MouseLeftButtonDown += (sender, args) => OnSelected();
        }
Example #2
0
        protected override void Init()
        {
            _movingBody   = Owner.Components.Get <MovingBody>();
            _transform    = Owner.Components.Get <TransformComponent>();
            _spriteRender = Owner.Components.Get <SpriteRenderComponent>();
            _halfSize     = _spriteRender.Sprite.Bounds.Size / 2;

            _boundingBox              = Owner.Components.Get <BoundingBoxComponent>();
            _boundingBox.OnCollision += (sender, collidedWith) =>
            {
                if (collidedWith.Owner.Components.TryGet <AsteroidBrain>(out var _))
                {
                    this.Stats.Health--;
                    if (0 == this.Stats.Health)
                    {
                        this.Owner.Enabled = false;
                        this.OnDeath?.Invoke(this.Owner);
                    }
                }
            };
        }