Ejemplo n.º 1
0
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                // Clear the target.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);

                // Draw a block of text that will be clipped against the specified layout rectangle.
                d2dContext.FillRectangle(new RectangleF(50, 50, 200, 200), backgroundBrush);
                d2dContext.DrawText("This text is long enough to overflow the designed region but will be clipped to the containing rectangle. Lorem ipsum dolor sit amet, consectetur adipiscing elit. ", textFormat, new RectangleF(50, 50, 200, 200), textBrush, DrawTextOptions.Clip);

                // Draw a block of text that will overflow the specified layout rectangle.
                d2dContext.FillRectangle(new RectangleF(50, 300, 200, 200), backgroundBrush);
                d2dContext.DrawText("However, this other text isn't going to be clipped: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean gravida dui id accumsan dictum.", textFormat, new RectangleF(50, 300, 200, 200), textBrush, DrawTextOptions.None);

                // Draw three lines of text with different measuring modes.
                d2dContext.FillRectangle(new RectangleF(300, 50, 400, 200), backgroundBrush);
                d2dContext.DrawText("MeasuringMode: Natural", textFormat, new RectangleF(300, 50, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.Natural);
                d2dContext.DrawText("MeasuringMode: GDI classic", textFormat, new RectangleF(300, 80, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.GdiClassic);
                d2dContext.DrawText("MeasuringMode: GDI natural", textFormat, new RectangleF(300, 110, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.GdiNatural);

                float layoutYOffset = (float)Math.Cos(layoutY) * 50.0f;

                // Draw moving text.
                d2dContext.FillRectangle(new RectangleF(300, 300, 400, 200), backgroundBrush);
                d2dContext.DrawTextLayout(new Vector2(300, 350 + layoutYOffset), textLayout1, textBrush);

                // Draw moving text without pixel snapping, thus giving a smoother movement.
                d2dContext.FillRectangle(new RectangleF(750, 300, 400, 200), backgroundBrush);
                d2dContext.DrawTextLayout(new Vector2(750, 350 + layoutYOffset), textLayout2, textBrush, DrawTextOptions.NoSnap);

                d2dContext.EndDraw();
                layoutY += 1.0f / 60.0f;

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Ejemplo n.º 2
0
 public void FillSolidRect(Windows.UI.Color color, Windows.Foundation.Rect rect)
 {
     // Create a solid color D2D brush.
     using (var brush = new SolidColorBrush(d2dContext, ConvertToColorF(color)))
     {
         // Draw a filled rectangle.
         d2dContext.FillRectangle(ConvertToRectF(rect), brush);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                // Clear the target and draw some geometry with the brushes we created.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);

                // Calculate the center of the screen
                int halfWidth  = this.swapChain.Description.ModeDescription.Width / 2;
                int halfHeight = this.swapChain.Description.ModeDescription.Height / 2;

                // Translate the origin of coordinates for drawing the bitmap filled rectangle
                d2dContext.Transform = Matrix3x2.Translation(halfWidth - 350, halfHeight);
                d2dContext.FillRectangle(new RectangleF(0, 0, 700, 70), terrainBrush);

                // Translate again for drawing the player bitmap
                d2dContext.Transform = Matrix3x2.Translation(halfWidth, halfHeight - playerBitmap.Size.Height);
                d2dContext.DrawBitmap(playerBitmap, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
                d2dContext.EndDraw();

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                // Clear the target and draw some geometry with the brushes we created.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);
                d2dContext.FillRectangle(new RectangleF(50, 50, 450, 150), solidBrush);
                d2dContext.FillRoundedRectangle(new RoundedRectangle()
                {
                    Rect    = new RectangleF(50, 250, 450, 150),
                    RadiusX = 10,
                    RadiusY = 10
                }, linearGradientBrush);
                d2dContext.FillEllipse(new Ellipse(new Vector2(250, 525), 100, 100), radialGradientBrush);
                d2dContext.EndDraw();

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Ejemplo n.º 5
0
        public virtual void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            context.DrawRectangle(screenSize.ApplyTo(GamesParams.Margin0.ToRectangleWith(GamesParams.Margin1)), GamesParams.ObstaclesColor, 2);

            _gameTime += dt;

            if (!_gameManager.IsTraining)
            {
                const float u = 1.00f;
                if (_gameTime < u && !AfterStartFreeze)
                {
                    var op = 1 - _gameTime / u;
                    var hideBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White,
                                                        new BrushProperties { Opacity = op });
                    context.FillRectangle(screenSize.ApplyTo(new RectangleF(0, 0, 1, 1)), hideBrush);
                }
                else
                {
                    AfterStartFreeze = true;
                }

                if (_gameTime > _gameMaxTime - u)
                {
                    var op = 1 - (_gameMaxTime - _gameTime) / u;
                    var hideBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Colors.White,
                                                        new BrushProperties { Opacity = op });
                    context.FillRectangle(screenSize.ApplyTo(new RectangleF(0, 0, 1, 1)), hideBrush);
                }

                float bar;
                bar = _gameManager.IsTraining ? 1 : _gameTime / _gameMaxTime;
                _gameManager.Page.SetTimeRectangleWidth(bar);
                _gameManager.RedrawPointsAndLifes();

                if (_gameTime > _gameMaxTime)
                    _gameManager.Win(100);
            }
        }
Ejemplo n.º 6
0
        public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            if (AfterStartFreeze)
            {
                // Player moving
                _playerPos =
                    _playerPos.Add(_playerDir.Mul(_playerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
                                                                             GamesParams.Margin1.Sub(_padSize.Half()));

                // Ball moving
                _ballPos = _ballPos.Add(_ballDir.Mul(_ballSpd).Mul(dt));

                // Ball collision with borders
                if (!_ballPos.IsInside(GamesParams.Margin0.Add(_ballSize.Half()),
                                       GamesParams.Margin1.Sub(_ballSize.Half())))
                {
                    _ballDir.Y = -_ballDir.Y;

                    if (_ballPos.X < GamesParams.MarginX0 + 0.001f)
                    {
                        NewGame();
                        _gameManager.Die();
                        return;
                    }

                    if (_ballPos.X > GamesParams.MarginX1 - 0.001f)
                    {
                        _gameManager.Win(500);
                        _ballPos = new Point(0.5f, 0.5f);
                        _ballDir = new Point(1.0f, 0.0f).AddNoise().Normalise();
                        return;
                    }
                }

                _ballPos = _ballPos.Clamp(GamesParams.Margin0.Add(_ballSize.Half()),
                                          GamesParams.Margin1.Sub(_ballSize.Half()));

                // Ball collision with player pad
                if (_ballPos.IsInside(_playerPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
                                      _playerPos.Add(_padSize.Half()).Add(_ballSize.Half())))
                {
                    _ballDir.X = 1;
                    _ballDir.Y = _ballPos.Sub(_playerPos).Y/_padSize.Half().Y;
                    _ballDir = _ballDir.Normalise();

                    _ballSpd += _ballSpdInc;

                    _gameManager.AddPoints(75);
                }

                // Ball collision with enemy pad
                if (_ballPos.IsInside(_enemyPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
                                      _enemyPos.Add(_padSize.Half()).Add(_ballSize.Half())))
                {
                    _ballDir.X = -1;
                    _ballDir.Y = _ballPos.Sub(_enemyPos).Y/_padSize.Half().Y;
                    _ballDir = _ballDir.Normalise();

                    _ballSpd += _ballSpdInc;
                }

                // Enemy moving
                if (Math.Abs(_ballPos.Y - _enemyPos.Y) < _padSize.Div(3).Y)
                {
                    _enemyDir.Y = 0;
                }
                else
                {
                    if (_ballPos.Y > _enemyPos.Y)
                        _enemyDir.Y = 1;
                    else
                        _enemyDir.Y = -1;

                    _enemyPos =
                        _enemyPos.Add(_enemyDir.Mul(_enemySpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
                                                                              GamesParams.Margin1.Sub(_padSize.Half()));
                }
            }

            // Drawing
            var playerBox = _playerPos.ToBox(_padSize);
            var enemyBox = _enemyPos.ToBox(_padSize);
            var ballBox = _ballPos.ToBox(_ballSize);

            context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);
            context.FillRectangle(screenSize.ApplyTo(enemyBox), GamesParams.EnemyColor);

            context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);

            base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
        }
        public bool SendFrame(TimeSpan elapsedTime)
        {
            using (var df = TakeNextFrameForSending())
            {
                if (!df.TryGetFrame(out BitmapFrameD2D1 frame))
                {
                    return(false);
                }

                _context2D.Target = frame.Bitmap;
                _context2D.BeginDraw();

                _context2D.Transform = Matrix3x2.Identity;
                _context2D.DrawBitmap(_backgroundBitmap, new RawRectangleF(0, 0, VideoFrameWidth, VideoFrameHeight),
                                      1, D2D1.BitmapInterpolationMode.NearestNeighbor);

                // Draw many balls to simulate high motion
                for (int i = 0; i < BallCount; ++i)
                {
                    var a   = 2 * Math.PI * elapsedTime.TotalSeconds + i * Math.PI / BallCount;
                    var h   = VideoFrameHeight - _ballEllipse.RadiusY;
                    var s   = (float)VideoFrameWidth / (BallCount + 1);
                    var y   = (float)(VideoFrameHeight - Math.Abs(Math.Sin(a) * h));
                    var pos = new RawVector2((i + 1) * s, y); // - _ballEllipse.RadiusX, y);

                    _context2D.Transform = MousePosition.HasValue
                        ? Matrix3x2.Translation(MousePosition.Value * new Vector2(VideoFrameWidth, VideoFrameHeight))
                        : Matrix3x2.Translation(pos);

                    _context2D.FillEllipse(_ballEllipse, _ballBrush);
                }

                if (_rulerOptions != null)
                {
                    _context2D.Transform = Matrix3x2.Identity;

                    // Draw the time markers and current time to measure latency
                    int markerCount  = _rulerOptions.MarkerCount;
                    int markerWidth  = _rulerOptions.MarkerWidth;
                    int markerHeight = _rulerOptions.MarkerHeight;
                    int markerOffset = markerWidth / 2;

                    var y = VideoFrameHeight - markerHeight;
                    _context2D.FillRectangle(new RectangleF(0, y, VideoFrameWidth, markerHeight), _timeRulerBrush);

                    for (int i = 0; i < markerCount; ++i)
                    {
                        var x = markerOffset + i * (VideoFrameWidth - markerWidth) / markerCount;
                        var b = i % 10 == 0 ? _timeMarkerBrush2 : _timeMarkerBrush1;

                        var r = new RectangleF(x - markerOffset, y, markerWidth, markerHeight);
                        _context2D.FillRectangle(r, b);
                    }

                    // Draw current time
                    {
                        var duration = _rulerOptions.Duration.TotalMilliseconds;
                        var t        = elapsedTime.TotalMilliseconds % duration;
                        var i        = (float)(t * markerCount / duration);

                        var x = markerOffset + i * (VideoFrameWidth - markerWidth) / markerCount;
                        var r = new RectangleF(x - markerOffset, y, markerWidth, markerHeight);
                        _context2D.FillRectangle(r, _currentTimeBrush);
                    }
                }

                _context2D.EndDraw();
                _context2D.Target = null;

                return(true);
            }
        }
Ejemplo n.º 8
0
        public void DrawRectangle(RectangleVisual visual)
        {
            var brush = new SolidColorBrush(_deviceContext, new SharpDX.Color(visual.Color.R, visual.Color.G, visual.Color.B));

            _deviceContext.FillRectangle(new RectangleF(visual.X, visual.Y, visual.Width, visual.Height), brush);
        }
Ejemplo n.º 9
0
        public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            if (AfterStartFreeze)
            {
                // Player moving
                _playerPos =
                    _playerPos.Add(_playerDir.Mul(_playerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
                                                                             GamesParams.Margin1.Sub(_padSize.Half()));

                // Ball moving
                var oldBallPos = _ballPos;
                _ballPos = _ballPos.Add(_ballDir.Mul(_ballSpd).Mul(dt));

                // Ball collision with borders
                if (!_ballPos.IsInside(GamesParams.Margin0.Add(_ballSize.Half()),
                                       GamesParams.Margin1.Sub(_ballSize.Half())))
                {
                    if (_ballPos.X - GamesParams.MarginX0 < _ballPos.Y - GamesParams.MarginY0 ||
                        GamesParams.MarginX1 - _ballPos.X < _ballPos.Y - GamesParams.MarginY0)
                        _ballDir.X = -_ballDir.X;
                    else
                        _ballDir.Y = -_ballDir.Y;

                    if (_ballPos.Y > GamesParams.MarginY1 - 0.01f)
                    {
                        _playerPos =
                            new Point(0.5f, GamesParams.MarginY1).Clamp(GamesParams.Margin0.Add(_padSize.Half()),
                                                                        GamesParams.Margin1.Sub(_padSize.Half()));
                        _ballPos = _playerPos.Sub(new Point(0, 0.1f));
                        _ballDir = new Point(0.0f, -1.0f).AddNoise().Normalise();
                        _gameManager.Die();
                        return;
                    }
                }

                _ballPos = _ballPos.Clamp(GamesParams.Margin0.Add(_ballSize.Half()),
                                          GamesParams.Margin1.Sub(_ballSize.Half()));

                // Ball collision with player pad
                if (_ballPos.IsInside(_playerPos.Sub(_padSize.Half()).Sub(_ballSize.Half()),
                                      _playerPos.Add(_padSize.Half()).Add(_ballSize.Half())))
                {
                    _ballDir.Y = -1;
                    _ballDir.X = _ballPos.Sub(_playerPos).X/_padSize.Half().X;
                    _ballDir = _ballDir.Normalise();

                    _ballSpd += _ballSpdInc;
                }

                // Ball collision with player pad
                foreach (var block in _blockPos)
                {
                    if (_ballPos.IsInside(block.Sub(_blockSize.Half()).Sub(_ballSize.Half()),
                                          block.Add(_blockSize.Half()).Add(_ballSize.Half())))
                    {
                        if (oldBallPos.X < block.Sub(_blockSize.Half()).Sub(_ballSize.Half()).X ||
                            oldBallPos.X > block.Add(_blockSize.Half()).Add(_ballSize.Half()).X)
                            _ballDir.X = -_ballDir.X;
                        else
                            _ballDir.Y = -_ballDir.Y;

                        block.X = -100;
                        block.Y = -100;

                        _gameManager.AddPoints(100);
                    }
                }
            }

            // Drawing
            var anyBlock = false;
            foreach (var block in _blockPos)
            {
                if (block.X < 0)
                    continue;

                anyBlock = true;
                var box = block.ToBox(_blockSize);
                context.FillRectangle(screenSize.ApplyTo(box), GamesParams.EnemyColor);
            }

            if (!anyBlock)
            {
                NewGame();
                _gameManager.Win(3000);
                return;
            }

            var playerBox = _playerPos.ToBox(_padSize);
            var ballBox = _ballPos.ToBox(_ballSize);
            context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);
            context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);

            base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
        }
Ejemplo n.º 10
0
 public void FillRectangle(RectangleF rectangle, Brush brush)
 {
     deviceContext.FillRectangle(Convert(rectangle), brush);
 }
Ejemplo n.º 11
0
        public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            if (AfterStartFreeze)
            {
                _timeToNextPossibleJump -= dt;

                if (_jumpTimer >= 0)
                {
                    _jumpTimer += dt * JumpSpeed;
                    _playerPos.Y = GroundY - _playerSize.Y / 2 - (float)Math.Sin(_jumpTimer) * JumpHeight;

                    if (_jumpTimer > Math.PI)
                    {
                        _playerPos.Y = GroundY - _playerSize.Y / 2;
                        _jumpTimer = -1;
                    }
                }
                else
                {
                    _canWin -= dt;
                    if (_canWin < 0)
                    {
                        _canWin = 1000;
                        _gameManager.Win(300);
                        return;
                    }
                }

                // Hole moving
                _holePos = _holePos.Add(_holeDir.Mul(_holeSpd).Mul(dt));
                if (_holePos.X + _holeSize.X / 2 <= GamesParams.MarginX0)
                {
                    AddNewObstacle();
                }
                if (_holePos.X < _playerPos.X && _canWin > 100)
                    _canWin = 0.5f;

                // Ball collision with player pad
                if (_holePos.IsInside(_playerPos.Sub(_playerSize.Half()).Sub(_holeSize.Half()),
                                      _playerPos.Add(_playerSize.Half()).Add(_holeSize.Half())))
                {
                    NewGame();
                    _gameManager.Die();
                    return;
                }
            }

            // Drawing
            context.FillRectangle(screenSize.ApplyTo(new RectangleF(GamesParams.MarginX0, GroundY, GamesParams.MarginX1, GamesParams.MarginY1)), GamesParams.ObstaclesColor);

            var holeBox = _holePos.ToBox(_holeSize);
            if (holeBox.Left < GamesParams.MarginX1)
            {
                if (holeBox.Left < GamesParams.MarginX0)
                    holeBox.Left = GamesParams.MarginX0;

                if (holeBox.Right > GamesParams.MarginX1)
                    holeBox.Right = GamesParams.MarginX1;

                context.FillRectangle(screenSize.ApplyTo(holeBox), _holeIsStone ? GamesParams.ObstaclesColor : GamesParams.BackgroundColor);
            }
            var playerBox = _playerPos.ToBox(_playerSize);
            context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);

            base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
        }
Ejemplo n.º 12
0
        public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            if (AfterStartFreeze)
            {
                // Player moving
                _snakePos = _snakePos.Add(_snakeDir.Mul(_snakeSpd).Mul(dt));

                _sumDt += dt;
                if (_sumDt > 0.05)
                {
                    var s0 = _snakeLastPos;
                    var s1 = _snakePos;
                    var it = s1.Sub(s0);
                    var lp = Math.Round(it.Length()/_snakePartSize.Mul(0.5f).X);
                    it = it.Normalise().Mul(_snakePartSize.Mul(0.5f));
                    var pp = s0;
                    while (lp-- > 0)
                    {
                        // Eating apple
                        if (pp.Sub(_apple).Length() < _snakePartSize.X/2 + _appleSize.X/2)
                        {
                            _snakePossibleSize += 25;
                            _snakeSpd += 0.0125f;
                            PlaceNewApple();
                            _gameManager.Win(500);
                            return;
                        }

                        // Collision with borders
                        if (!pp.IsInside(GamesParams.Margin0.Add(_snakePartSize.Half()),
                                         GamesParams.Margin1.Sub(_snakePartSize.Half())))
                        {
                            NewGame();
                            _gameManager.Die();
                            return;
                        }

                        // Self collision
                        var mm = _snake.Count - 3;
                        if (
                            _snake.TakeWhile(snakePart => --mm > 0).Any(
                                snakePart => snakePart.Sub(pp).Length() < _snakePartSize.X/3*2))
                        {
                            NewGame();
                            _gameManager.Die();
                            return;
                        }

                        _snake.Add(new Point(pp.X, pp.Y));
                        pp = pp.Add(it);
                        _sumDt = 0;
                        _snakeLastPos = _snakePos;
                    }

                    while (_snake.Count > _snakePossibleSize)
                    {
                        _snake.RemoveAt(0);
                    }
                }
            }

            // Drawing
            foreach (var snakePart in _snake)
            {
                var box = snakePart.ToBox(_snakePartSize);
                context.FillRectangle(screenSize.ApplyTo(box), GamesParams.PlayerColor);
            }

            var headBox = _snake.Last().ToBox(_snakePartSize.Mul(0.5f));
            context.FillRectangle(screenSize.ApplyTo(headBox), GamesParams.AdditionalColor);

            var appleBox = _apple.ToBox(_appleSize);
            context.FillRectangle(screenSize.ApplyTo(appleBox), GamesParams.AdditionalColor);
            base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
        }
Ejemplo n.º 13
0
        public override void Update(DeviceContext context, TargetBase target, DeviceManager deviceManager, Point screenSize, float dt, float elapsedTime)
        {
            if (AfterStartFreeze)
            {
                _timeToNextPossibleShoot -= dt;
                if (_isShootButtonPressed && _timeToNextPossibleShoot <= 0)
                {
                    var p = _playerPos.Sub(new Point(0, 0.01f));
                    _bulletPos.Add(p);

                    _timeToNextPossibleShoot = ShootInterval;
                }

                // Player moving
                _playerPos =
                    _playerPos.Add(_playerDir.Mul(PlayerSpd).Mul(dt)).Clamp(GamesParams.Margin0.Add(_playerSize.Half()),
                                                                            GamesParams.Margin1.Sub(_playerSize.Half()));

                // Enemies
                for (var e = 0; e < _enemyPos.Count; ++e)
                {
                    var enemyPos = _enemyPos[e];

                    // Enemy reach bottom line
                    _enemyPos[e] = enemyPos.Add(_enemyDir.Mul(EnemySpd).Mul(dt));
                    enemyPos = _enemyPos[e];

                    if (enemyPos.IsInside(GamesParams.Margin0.Sub(_enemySize.Half()).Add(new Point(0, 1)),
                                          GamesParams.Margin1.Add(_enemySize.Half()).Add(new Point(0, 1))))
                    {
                        AddEnemy(e);
                        AddEnemy();
                        AddEnemy();
                    }

                    // Enemy collision with player
                    if (enemyPos.IsInside(_playerPos.Sub(_playerSize.Half()).Sub(_playerSize.Half()),
                                          _playerPos.Add(_playerSize.Half()).Add(_playerSize.Half())))
                    {
                        NewGame();
                        _gameManager.Die();
                        return;
                    }
                }

                // Bullet moving
                for (var i = 0; i < _bulletPos.Count; ++i)
                {
                    var bulletPos = _bulletPos[i];
                    _bulletPos[i] = bulletPos.Add(_bulletDir.Mul(BulletSpd).Mul(dt));
                    bulletPos = _bulletPos[i];

                    // Bullet collision with borders
                    if (!bulletPos.IsInside(GamesParams.Margin0.Sub(_bulletSize.Half()),
                                            GamesParams.Margin1.Add(_bulletSize.Half())))
                    {
                        _bulletPos.RemoveAt(i);
                    }

                    // Bullet collision with enemies
                    for (var e = 0; e < _enemyPos.Count; ++e)
                    {
                        var enemyPos = _enemyPos[e];
                        if (bulletPos.IsInside(enemyPos.Sub(_enemySize.Half()).Sub(_bulletSize.Half()),
                                               enemyPos.Add(_enemySize.Half()).Add(_bulletSize.Half())))
                        {
                            _bulletPos.RemoveAt(i);
                            AddEnemy(e);
                            AddEnemy();
                            _gameManager.AddPoints(50);
                            break;
                        }
                    }
                }
            }

            // Drawing
            foreach (var bullet in _bulletPos)
            {
                var ballBox = bullet.ToBox(_bulletSize);
                context.FillRectangle(screenSize.ApplyTo(ballBox), GamesParams.AdditionalColor);
            }

            foreach (var enemy in _enemyPos)
            {
                var box = enemy.ToBox(_enemySize);
                if (box.Left > GamesParams.MarginX1 || box.Right < GamesParams.MarginX0 || box.Bottom < GamesParams.MarginY0 || box.Top > GamesParams.MarginY1)
                    continue;

                if (box.Left < GamesParams.MarginX0)
                    box.Left = GamesParams.MarginX0;
                if (box.Right > GamesParams.MarginX1)
                    box.Right = GamesParams.MarginX1;
                if (box.Top < GamesParams.MarginY0)
                    box.Top = GamesParams.MarginY0;
                if (box.Bottom > GamesParams.MarginY1)
                    box.Bottom = GamesParams.MarginY1;

                context.FillRectangle(screenSize.ApplyTo(box), GamesParams.EnemyColor);
            }

            var playerBox = _playerPos.ToBox(_playerSize);
            context.FillRectangle(screenSize.ApplyTo(playerBox), GamesParams.PlayerColor);

            base.Update(context, target, deviceManager, screenSize, dt, elapsedTime);
        }