示例#1
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _spriteBatch.Begin();

            _spriteBatch.Draw(_background, Vector2.Zero, Color.White);

            _spriteBatch.Draw(_clouds, _cloudPosition, Color.White);

            _spriteBatch.Draw(_clouds, _cloudPosition - _cloudOffset, Color.White);

            _map.Draw(gameTime, _spriteBatch, Vector2.Zero);

            foreach (Player en in Players)
            {
                en.Draw(gameTime, _spriteBatch);
            }

            _spriteBatch.End();

            _spriteBatch.Begin();
            _gui.Draw(gameTime, _spriteBatch, _game.Window.ClientBounds);
            _spriteBatch.End();
        }
        /// <summary>
        /// Draws current active levels and their entities.
        /// </summary>
        /// <param name="gameTime">Game time.</param>
        public void Draw(GraphicsDevice graphicsDevice, GameTime gameTime, SpriteBatch spriteBatch, Rectangle clientBounds)
        {
            Vector2?cameraPos = null;

            if (!CurrentLevels.Any())
            {
                return;
            }

            var split = CurrentLevels.Count() > 1;

            if (!split)
            {
                var level = CurrentLevels.First();
                if (level.Players.Count() > 1)
                {
                    var p1    = level.Players.First();
                    var p2    = level.Players.Last();
                    var p1Pos = p1.CenterPosition;
                    var p2Pos = p2.CenterPosition;
                    var dist  = p1Pos - p2Pos;
                    if (dist.X > clientBounds.Width - p1.CollisionRect.Width - p2.CollisionRect.Width || dist.Y > clientBounds.Height - p1.CollisionRect.Height - p2.CollisionRect.Height || p1.TransitioningToLevel != 0 || p2.TransitioningToLevel != 0)
                    {
                        split = true;
                    }
                    else
                    {
                        cameraPos = (p2Pos + p1Pos) / 2;
                    }
                }
            }

            if (split)
            {
                var       oldViewport = graphicsDevice.Viewport;
                Rectangle?pBounds     = null;
                foreach (var pInfo in CurrentLevels.SelectMany(l => l.Players.Select(p => new { Player = p, Level = l })).OrderBy(p => p.Player.DisplayName))
                {
                    if (pBounds == null)
                    {
                        pBounds = new Rectangle(0, 0, clientBounds.Width / 2, clientBounds.Height);
                    }
                    else
                    {
                        pBounds = new Rectangle(clientBounds.Width / 2, 0, clientBounds.Width / 2, clientBounds.Height);
                    }

                    graphicsDevice.Viewport = new Viewport(pBounds.Value);

                    var transformMatrix = Matrix.CreateScale(new Vector3(1, 1, 0));
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, transformMatrix);

                    var lv = pInfo.Level;

                    if (pInfo.Player.TransitioningToLevel != 0)
                    {
                        SlideScreen(gameTime, spriteBatch, pBounds.Value, lv, pInfo.Player);
                    }
                    else
                    {
                        Vector2 camera = GetCameraPosition(pInfo.Player.CenterPosition, lv.Map.PixelSize, pBounds.Value);
                        lv.Draw(gameTime, spriteBatch, camera);
                    }

                    #region GUI Drawing
                    int       guiSize = 100;
                    Rectangle GUIRect = new Rectangle(pBounds.Value.X, pBounds.Value.Y, pBounds.Value.Width, guiSize);
                    _gui.Draw(spriteBatch, GUIRect, new[] { pInfo.Player }, clientBounds);
                    #endregion GUI Drawing

                    //Title Card
                    if (_cards.ContainsKey(pInfo.Player))
                    {
                        _cards[pInfo.Player].Draw(gameTime, spriteBatch, pBounds.Value);
                    }

                    spriteBatch.End();
                }

                graphicsDevice.Viewport = oldViewport;
            }
            else
            {
                spriteBatch.Begin();
                var lv     = CurrentLevels.First();
                var player = lv.Players.First();

                if (player.TransitioningToLevel == 0)
                {
                    Vector2 camera = GetCameraPosition(cameraPos ?? lv.Players.First().CenterPosition, lv.Map.PixelSize, clientBounds);
                    lv.Draw(gameTime, spriteBatch, camera);
                }
                else
                {
                    SlideScreen(gameTime, spriteBatch, clientBounds, lv, player);
                }

                #region GUI Drawing
                int       guiSize = 100;
                Rectangle GUIRect = new Rectangle(clientBounds.X, clientBounds.Y, clientBounds.Width, guiSize);
                _gui.Draw(spriteBatch, GUIRect, Players, clientBounds);
                #endregion GUI Drawing

                //Title Card
                if (_cards.ContainsKey(player))
                {
                    _cards[player].Draw(gameTime, spriteBatch, clientBounds);
                }

                spriteBatch.End();
            }
        }
示例#3
0
 public void DrawGUI()
 {
     GameGUI.Draw();
 }