Пример #1
0
        private void Render(Window window)
        {
            #region Draw gameplay stuff.

            App.Graphics.Clear(Buffer, Color.FromHexStringRGB("#150e22"));

            // Push camera offset.
            Batch.PushMatrix(Matrix3x2.CreateTranslation(-Camera + shake));

            // Draw gameplay objects.
            world.Render(Batch);

            // Draw debug colliders.
            if (drawColliders)
            {
                var collider = world.First <Collider>();

                while (collider != null)
                {
                    collider.Render(Batch);
                    collider = (Collider)collider.Next;
                }
            }

            // Hacky start / end screen text.
            if (Room == new Point2(0, 0) || lastRoom == new Point2(0, 0))
            {
                var w   = Content.Font.WidthOf(Title);
                var pos = new Point2((Width - (int)w) / 2, 20);
                Batch.Text(Content.Font, Title, pos + new Point2(0, 1), Color.Black);
                Batch.Text(Content.Font, Title, pos, Color.White);

                w      = Content.Font.WidthOf(Controls);
                pos.X  = (Width - (int)w) / 2;
                pos.Y += 20;
                Batch.Text(Content.Font, Controls, pos, Color.White * 0.25f);
            }
            else if (Room == new Point2(13, 0))
            {
                var w   = Content.Font.WidthOf(Ending);
                var pos = new Point2(Room.X * Width + Width / 2, Room.Y * Height + 20);
                Batch.Text(Content.Font, Ending, pos + new Point2(0, 1), Color.Black);
                Batch.Text(Content.Font, Ending, pos, Color.White);
            }

            // End camera offset.
            Batch.PopMatrix();

            // Draw the health.
            var player = world.First <Player>();

            if (player != null)
            {
                var hearts = Content.FindSprite("heart");
                var full   = hearts.GetAnimation("full");
                var empty  = hearts.GetAnimation("empty");

                Point2 pos = new Point2(0, Height - 16);
                Batch.Rect(new Rect(pos.X, pos.Y + 7, 40, 4), Color.Black);

                for (int i = 0; i < Player.MAX_HEALTH; i++)
                {
                    if (player.Health >= i + 1)
                    {
                        Batch.Image(full.Frames[0].Image, pos, Color.White);
                    }
                    else
                    {
                        Batch.Image(empty.Frames[0].Image, pos, Color.White);
                    }

                    pos.X += 12;
                }
            }

            // Draw FPS.
            if (drawColliders)
            {
                var fpsText = "FPS: " + Time.FPS;
                var w       = Content.Font.WidthOf(fpsText);
                var pos     = new Point2((Width - (int)w) - 5, 5);
                Batch.Text(Content.Font, fpsText, pos, Color.White);
            }

            // Draw the gameplay buffer.
            Batch.Render(Buffer);
            Batch.Clear();

            #endregion

            #region Draw buffer to the screen.

            float scale = Math.Min(
                App.Window.RenderWidth / (float)Buffer.RenderWidth,
                App.Window.RenderHeight / (float)Buffer.RenderHeight
                );

            Vector2 screenCenter = new Vector2(App.Window.RenderWidth, App.Window.RenderHeight) / 2;
            Vector2 bufferCenter = new Vector2(Buffer.RenderWidth, Buffer.RenderHeight) / 2;

            App.Graphics.Clear(window, Color.Black);
            Batch.PushMatrix(Mat3x2Ext.CreateTransform(screenCenter, bufferCenter, Vector2.One * scale, 0));
            Batch.Image(Buffer.Attachments[0], Vector2.Zero, Color.White);
            Batch.PopMatrix();
            Batch.Render(window);
            Batch.Clear();

            #endregion
        }