Beispiel #1
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Gray);

            _spriteBatch.Begin(samplerState: SamplerState.AnisotropicClamp, transformMatrix: _camera.GetViewMatrix());

            if (_fieldRenderer != null)
            {
                _spriteBatch.Draw(_fieldRenderer.RenderTarget, Vector2.Zero, null, Color.White, 0,
                                  Vector2.Zero,
                                  Vector2.One, SpriteEffects.None, 0.0f);
            }

            var mousePos = _camera.ScreenToWorld(InputManager.MousePosition);

            if ((_gameStateManager.CurrentState == GameState.Playing ||
                 _gameStateManager.CurrentState == GameState.NewGame) &&
                mousePos.X > 0 &&
                mousePos.Y > 0 &&
                mousePos.X < _field.Width * _field.CellSize &&
                mousePos.Y < _field.Height * _field.CellSize)
            {
                // Drawing a gray cell appended to the cursor

                var mousePosSnapped = new Vector2(mousePos.X - mousePos.X % _field.CellSize, mousePos.Y - mousePos.Y % _field.CellSize);
                if (InputManager.IsMouseButtonUp(MouseButton.Left)) // Draw an overlay
                {
                    _spriteBatch.FillRectangle(mousePosSnapped, new Size2(_field.CellSize, _field.CellSize), Color.Black * 0.25f);
                }
                else // Draw an empty cell just for sake of beauty
                {
                    // _spriteBatch.FillRectangle(mousePosSnapped, new Size2(_field.CellSize, _field.CellSize), Color.LightGray);
                    var positions = _field.GetSuitableCellPositionsAt((int)mousePos.X / _field.CellSize, (int)mousePos.Y / _field.CellSize);

                    foreach (var position in positions)
                    {
                        _spriteBatch.FillRectangle(position.ToVector2() * _field.CellSize, new Size2(_field.CellSize, _field.CellSize), Color.LightGray);
                        _spriteBatch.DrawRectangle(position.ToVector2() * _field.CellSize, new Size2(_field.CellSize, _field.CellSize), Color.Gray);
                    }
                }
            }

            if (_gameStateManager.HasLost)
            {
                _spriteBatch.FillRectangle(Vector2.Zero, new Size2(_field.Width * _field.CellSize, _field.Height * _field.CellSize), _loseColor);
            }

            _spriteBatch.End();

            /*_spriteBatch.Begin();
             *
             * _spriteBatch.FillRectangle(Vector2.Zero, new Size2(GraphicsDevice.Viewport.Width, 48), Color.DarkGray);
             * _spriteBatch.DrawString(_mainFont, _secondsElapsed.ToString("F0", CultureInfo.InvariantCulture), Vector2.One, Color.Black);
             *
             * _spriteBatch.End();*/

            RenderImGuiLayout(gameTime);
        }