Beispiel #1
0
        public override void Draw(GameTime gameTime, Frame frame) {
            ClearBatch.AddNew(frame, 4, Color.Black, Materials.Clear);

            using (var gb = GeometryBatch<VertexPositionColor>.New(frame, 5, Materials.ScreenSpaceGeometry)) {
                gb.AddGradientFilledQuad(
                    Vector2.Zero, new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight),
                    Color.DarkSlateGray, Color.DarkSlateGray,
                    Color.SlateBlue, Color.SlateBlue
                );
            }

            using (var gb = GeometryBatch<VertexPositionColor>.New(frame, 6, Materials.ScreenSpaceGeometry)) {
                var alphaBlack = new Color(0, 0, 0, 192);
                var alphaBlack2 = new Color(0, 0, 0, 64);

                gb.AddQuadBorder(
                    Playfield.Bounds.TopLeft + new Vector2(32 + 24, 0), 
                    Playfield.Bounds.BottomRight + new Vector2(-32 - 24, 0), 
                    alphaBlack2, alphaBlack, 24
                );
            }

            // Render the contents of the trail buffer to the screen using additive blending
            using (var bb = BitmapBatch.New(frame, 7, Materials.Trail)) {
                bb.Add(new BitmapDrawCall(
                    TrailBuffer, Vector2.Zero, (float)TrailScale
                ));
            }

            // Render the paddles and ball to both the framebuffer and the trail buffer (note the different layer values)
            using (var gb = GeometryBatch<VertexPositionColor>.New(frame, 8, Materials.ScreenSpaceGeometry))
            using (var trailBatch = GeometryBatch<VertexPositionColor>.New(frame, 2, Materials.ScreenSpaceGeometry)) {
                foreach (var paddle in Paddles) {
                    gb.AddFilledQuad(
                        paddle.Bounds.TopLeft, paddle.Bounds.BottomRight, Color.White
                    );
                    gb.AddQuadBorder(
                        paddle.Bounds.TopLeft, paddle.Bounds.BottomRight, Color.Black, Color.Black, 2.25f
                    );

                    trailBatch.AddFilledQuad(
                        paddle.Bounds.TopLeft, paddle.Bounds.BottomRight, Color.White
                    );
                }

                gb.AddFilledRing(Ball.Position, 0.0f, Ball.Radius, Color.White, Color.White);
                gb.AddFilledRing(Ball.Position, Ball.Radius, Ball.Radius + 2.0f, Color.Black, Color.Black);

                trailBatch.AddFilledRing(Ball.Position, 0.0f, Ball.Radius, Color.White, Color.White);
            }

            // Render the score values using a stringbatch (unfortunately this uses spritebatch to render spritefonts :( )
            using (var sb = StringBatch.New(frame, 9, Materials.ScreenSpaceBitmap, SpriteBatch, Font)) {
                var drawCall = new StringDrawCall(
                    String.Format("Player 1: {0:00}", Scores[0]),
                    new Vector2(16, 16),
                    Color.White
                );

                sb.Add(drawCall.Shadow(Color.Black, 1));
                sb.Add(drawCall);

                drawCall.Text = String.Format("Player 2: {0:00}", Scores[1]);
                drawCall.Position.X = Graphics.PreferredBackBufferWidth - 16 - sb.Measure(ref drawCall).X;

                sb.Add(drawCall.Shadow(Color.Black, 1));
                sb.Add(drawCall);
            }

            // The first stage of our frame involves selecting the trail buffer as our render target (note that it's layer 0)
            SetRenderTargetBatch.AddNew(frame, 0, TrailBuffer);

            if (FirstFrame) {
                // If it's the first time we've rendered, we erase the trail buffer since it could contain anything
                ClearBatch.AddNew(frame, 1, Color.Black, Materials.Clear);
                FirstFrame = false;
            } else {
                // Otherwise, we fade out the contents of the trail buffer
                using (var gb = GeometryBatch<VertexPositionColor>.New(frame, 1, Materials.SubtractiveGeometry)) {
                    gb.AddFilledQuad(
                        new Bounds(Vector2.Zero, new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight)), 
                        new Color(12, 12, 12)
                    );
                }
            }
            
            // After the trail buffer has been updated, we turn it off and begin rendering to the framebuffer. Note layer 3.
            SetRenderTargetBatch.AddNew(frame, 3, null);
        }
Beispiel #2
0
        private void DrawHud (Frame frame) {
            Rectangle titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea;
            Vector2 hudLocation = new Vector2(titleSafeArea.X, titleSafeArea.Y);
            Vector2 center = new Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
                                         titleSafeArea.Y + titleSafeArea.Height / 2.0f);

            // Draw time remaining. Uses modulo division to cause blinking when the
            // player is running out of time.
            string timeString = "TIME: " + level.TimeRemaining.Minutes.ToString("00") + ":" + level.TimeRemaining.Seconds.ToString("00");
            Color timeColor;
            if (level.TimeRemaining > WarningTime ||
                level.ReachedExit ||
                (int)level.TimeRemaining.TotalSeconds % 2 == 0) {
                timeColor = Color.Yellow;
            } else {
                timeColor = Color.Red;
            }

            using (var bb = BitmapBatch.New(frame, 100, materials.ScreenSpaceBitmap))
            using (var sb = StringBatch.New(frame, 100, materials.ScreenSpaceBitmap, spriteBatch, this.hudFont)) {
                var sdc = new StringDrawCall(
                    timeString, hudLocation, timeColor
                );

                sb.Add(sdc.Shadow(Color.Black, 1.0f));
                sb.Add(sdc);

                // Draw score
                float timeHeight = hudFont.MeasureString(timeString).Y;
                sdc.Text = "SCORE: " + level.Score.ToString();
                sdc.Position += new Vector2(0.0f, timeHeight * 1.2f);
                sdc.Color = Color.Yellow;

                sb.Add(sdc.Shadow(Color.Black, 1.0f));
                sb.Add(sdc);

                // Determine the status overlay message to show.
                Texture2D status = null;
                if (level.TimeRemaining == TimeSpan.Zero) {
                    if (level.ReachedExit) {
                        status = winOverlay;
                    } else {
                        status = loseOverlay;
                    }
                } else if (!level.Player.IsAlive) {
                    status = diedOverlay;
                }

                if (status != null) {
                    // Draw status message.
                    Vector2 statusSize = new Vector2(status.Width, status.Height);
                    bb.Add(new BitmapDrawCall(status, center - statusSize / 2));
                }
            }
        }