コード例 #1
0
        public override void Draw(GameTime gameTime, Frame frame)
        {
            var ir = new ImperativeRenderer(frame, Materials);
            ir.AutoIncrementLayer = true;

            ir.Clear(color: ClearColor);

            var rect1 = new Rectangle(0, 0, 32, 32);
            var rect2 = new Rectangle(1, 1, 30, 30);

            var drawSet = (Action<Rectangle, float>)((r, y) => {
                DrawRow(ref ir, 0f, y + 0f, SamplerState.PointClamp, r);
                DrawRow(ref ir, 0.5f, y + 1 + 64f, SamplerState.PointClamp, r);
                DrawRow(ref ir, 0f, (y + 3 + 128) + 0.5f, SamplerState.PointClamp, r);

                DrawRow(ref ir, 0f, y + 5 + 192f, SamplerState.LinearClamp, r);
                DrawRow(ref ir, 0.5f, y + 7 + 256f, SamplerState.LinearClamp, r);
                DrawRow(ref ir, 0f, (y + 9 + 320) + 0.5f, SamplerState.LinearClamp, r);
            });

            drawSet(rect1, 0f);

            drawSet(rect2, (70f*6));

            var cornerSamplers = SamplerState.LinearClamp;
            ir.Draw(TestTexture, new Vector2(Graphics.PreferredBackBufferWidth - 1, Graphics.PreferredBackBufferHeight - 1), origin: new Vector2(1, 1), samplerState: cornerSamplers);
            ir.Draw(TestTexture, new Vector2(0, Graphics.PreferredBackBufferHeight - 1), origin: new Vector2(0, 1), samplerState: cornerSamplers);
            ir.Draw(TestTexture, new Vector2(Graphics.PreferredBackBufferWidth - 1, 0), origin: new Vector2(1, 0), samplerState: cornerSamplers);
        }
コード例 #2
0
ファイル: Exploration.cs プロジェクト: kg/rlms2013
        public void Draw(Frame frame, ref ImperativeRenderer renderer)
        {
            if (!ContentLoaded)
                return;

            View.Draw(frame, ref renderer);

            renderer.Layer += 1;

            Handler.Draw(ref renderer);
        }
コード例 #3
0
        private void DrawRow(ref ImperativeRenderer ir, float x, float y, SamplerState samplerState)
        {
            var sourceRect = new Rectangle(1, 1, 30, 30);

            ir.Draw(TestTexture, x, y, sourceRect, samplerState: samplerState);
            x += 64f;
            ir.Draw(TestTexture, x, y, sourceRect, scaleX: 2f, scaleY: 2f, samplerState: samplerState);
            x += 96f;

            for (float r = 0.1f; r < Math.PI / 2f; r += 0.2f) {
                ir.Draw(TestTexture, x, y, sourceRect, rotation: r, samplerState: samplerState);

                x += 64f;
            }
        }
コード例 #4
0
        public override void Draw(GameTime gameTime, Frame frame)
        {
            var ir = new ImperativeRenderer(frame, Materials);
            ir.AutoIncrementLayer = true;

            ir.Clear(color: ClearColor);

            DrawRow(ref ir, 16f, 16f, SamplerState.PointClamp);
            DrawRow(ref ir, 16.5f, 16 + 64f, SamplerState.PointClamp);
            DrawRow(ref ir, 16f, (16 + 128) + 0.5f, SamplerState.PointClamp);

            DrawRow(ref ir, 16f, 16 + 192f, SamplerState.LinearClamp);
            DrawRow(ref ir, 16.5f, 16 + 256f, SamplerState.LinearClamp);
            DrawRow(ref ir, 16f, (16 + 320) + 0.5f, SamplerState.LinearClamp);
        }
コード例 #5
0
ファイル: Menu.cs プロジェクト: kg/rlms2013
        public static void DrawCursor(Game game, ref ImperativeRenderer renderer, Vector2 itemPosition, Vector2 menuSize, Vector2 itemSize)
        {
            var time = (float)Time.Seconds;
            var scale = Vector2.One;
            var offset = Arithmetic.Pulse(time, 0.6f, 0.75f);
            var origin = new Vector2(0.5f, 0.5f);
            var bounds = new Bounds(Vector2.Zero, Vector2.One);

            itemPosition.X -= (game.Cursor.Width * offset);
            itemPosition.Y += (itemSize.Y / 2.0f);
            var drawCall = new Squared.Render.BitmapDrawCall(
                game.Cursor, itemPosition, bounds, Color.White, scale, origin
            );

            renderer.Draw(ref drawCall);

            itemPosition.X += menuSize.X + (game.Cursor.Width * offset * 2.0f);
            drawCall.Position = itemPosition;
            drawCall.Mirror(true, false);

            renderer.Draw(ref drawCall);
        }
コード例 #6
0
ファイル: Textbox.cs プロジェクト: kg/rlms2013
        public void Draw(Frame frame, ref ImperativeRenderer renderer)
        {
            renderer.FillRectangle(Bounds.Expand(4, 4), Color.Black * 0.9f);
            renderer.Layer += 1;
            renderer.OutlineRectangle(Bounds.Expand(4, 4), Color.White);
            renderer.Layer += 1;

            int charactersLeft = DisplayedCharacterCount;

            foreach (var s in Strings) {
                int charactersToDraw = Math.Min(charactersLeft, s.Layout.Count);
                if (s.IsMu) {
                    var offset = new Vector2((float)BlippyRNG.NextDouble(-1, 1), (float)BlippyRNG.NextDouble(-1, 1));
                    var scale = (float)BlippyRNG.NextDouble(0.95f, 1.05f);
                    var rotation = (float)BlippyRNG.NextDouble(-0.04f, 0.04f);

                    var dc = s.Layout.DrawCalls.Array[s.Layout.DrawCalls.Offset];
                    dc.Position += offset;
                    dc.ScaleF = scale;
                    dc.Rotation = rotation;
                    dc.MultiplyColor *= (float)BlippyRNG.NextDouble(0.7f, 1.1f);

                    renderer.Draw(ref dc);
                } else {
                    renderer.DrawMultiple(s.Layout.Slice(0, charactersToDraw));
                }
                charactersLeft -= s.Length;
            }

            renderer.Layer += 1;

            if (AdvancePromptVisible) {
                var advancePromptPosition = Bounds.BottomRight;
                advancePromptPosition.Y -= Squared.Util.Arithmetic.PulseSine((float)(Squared.Util.Time.Seconds * 0.66), 0f, 24f);
                renderer.Draw(AdvancePromptIcon, advancePromptPosition, origin: new Vector2(0.85f, 0.8f));
            }

            renderer.Layer += 1;
        }
コード例 #7
0
ファイル: PongExample.cs プロジェクト: sq/Fracture
        public override void Draw(GameTime gameTime, Frame frame)
        {
            ClearBatch.AddNew(frame, 4, Materials.Clear, clearColor: new Color(16, 32, 48));

            var alphaGeometry = Materials.Get(Materials.ScreenSpaceGeometry, blendState: BlendState.AlphaBlend);

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

            using (var gb = GeometryBatch.New(frame, 6, alphaGeometry)) {
                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.New(frame, 8, alphaGeometry))
            using (var gb2 = GeometryBatch.New(frame, 9, alphaGeometry))
            using (var trailBatch = GeometryBatch.New(frame, 2, alphaGeometry)) {
                foreach (var paddle in Paddles) {
                    gb.AddFilledQuad(
                        paddle.Bounds.TopLeft, paddle.Bounds.BottomRight, Color.White
                    );
                    gb2.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);
                gb2.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 :( )
            {
                var ir = new ImperativeRenderer(frame, Materials, 10, blendState: BlendState.AlphaBlend);
                ir.DrawString(
                    Font, String.Format("Player 1: {0:00}", Scores[0]),
                    new Vector2(16, 16)
                );

                var player2Text = String.Format("Player 2: {0:00}", Scores[1]);
                ir.DrawString(
                    Font, player2Text,
                    new Vector2(Graphics.PreferredBackBufferWidth - 16 - Font.MeasureString(player2Text).X, 16)
                );
            }

            // 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, Materials.Clear, clearColor: Color.Black);
                FirstFrame = false;
            } else {
                // Otherwise, we fade out the contents of the trail buffer
                using (var gb = GeometryBatch.New(frame, 1, Materials.SubtractiveGeometry)) {
                    gb.AddFilledQuad(
                        new Bounds(Vector2.Zero, new Vector2(Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight)),
                        new Color(12, 12, 12, 0)
                    );
                }
            }

            // 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);
        }
コード例 #8
0
ファイル: PlatformerGame.cs プロジェクト: pakoito/Fracture
        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;
            }

            var renderer = new ImperativeRenderer(frame, materials, 100, blendState: BlendState.AlphaBlend);

            renderer.DrawString(hudFont, timeString, hudLocation, timeColor, sortKey: 1);
            renderer.DrawString(hudFont, timeString, hudLocation + Vector2.One, Color.Black, sortKey: 0);

            var timeHeight = hudFont.MeasureString(timeString).Y;
            hudLocation.Y = (float)Math.Floor(hudLocation.Y + (timeHeight * 1.2f));

            var scoreText = "SCORE: " + level.Score;
            renderer.DrawString(hudFont, scoreText, hudLocation, Color.Yellow, sortKey: 1);
            renderer.DrawString(hudFont, scoreText, hudLocation + Vector2.One, Color.Black, sortKey: 0);

            // 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);
                renderer.Draw(status, center - statusSize / 2);
            }
        }
コード例 #9
0
ファイル: Menu.cs プロジェクト: kg/rlms2013
        public virtual void Draw(Game game, ref ImperativeRenderer renderer, Vector2 itemPosition, Vector2 itemSize, bool selected)
        {
            if (Text == null)
                return;

            renderer.DrawString(
                Font, Text, itemPosition,
                (selected) ? Color.White : new Color(127, 127, 127, 255)
            );
        }
コード例 #10
0
ファイル: Menu.cs プロジェクト: kg/rlms2013
        public void Draw(Frame frame, ref ImperativeRenderer renderer)
        {
            var now = Time.Ticks;
            float alpha = (float)(TimeSpan.FromTicks(now - ShownWhen).TotalSeconds / FadeInTime);
            var color = new Color(
                alpha, alpha, alpha, alpha
            );

            renderer.Draw(new Squared.Render.BitmapDrawCall(
                Image, Center, new Bounds(Vector2.Zero, Vector2.One), color,
                Vector2.One, new Vector2(0.5f, 0.5f)
            ));
        }
コード例 #11
0
ファイル: Menu.cs プロジェクト: kg/rlms2013
        public void Draw(Frame frame, ref ImperativeRenderer renderer)
        {
            var size = Measure();
            var pos = new Vector2(Game.ViewportWidth - size.X, Game.ViewportHeight - size.Y) * new Vector2(0.5f, 0.5f);

            pos.X = (float)Math.Floor(pos.X);
            pos.Y = (float)Math.Floor(pos.Y);

            var menuBounds = new Bounds(
                pos - new Vector2(4, 4),
                pos + size + new Vector2(4, 4)
            );

            renderer.FillRectangle(
                menuBounds,
                new Color(0.0f, 0.0f, 0.0f, BackgroundOpacity)
            );
            renderer.Layer += 1;

            renderer.OutlineRectangle(
                menuBounds,
                Color.White
            );

            renderer.Layer += 1;

            for (int i = 0; i < Items.Count; i++) {
                var item = Items[i];
                var itemSize = item.Measure(Game);
                var selected = (i == SelectedIndex);

                item.Draw(Game, ref renderer, pos, itemSize, selected);

                if (selected)
                    DrawCursor(Game, ref renderer, pos, size, itemSize);

                pos.Y += itemSize.Y;
            }

            renderer.Layer += 1;
        }
コード例 #12
0
        private void DrawRow(ref ImperativeRenderer ir, float x, float y, SamplerState samplerState, Rectangle sourceRect)
        {
            var tlState = samplerState;
            if ((x == 0) && (y == 0))
                tlState = SamplerState.LinearClamp;

            ir.Draw(TestTexture, x, y, sourceRect, samplerState: tlState);
            x += 64f;
            ir.Draw(TestTexture, x, y, sourceRect, scaleX: 2f, scaleY: 2f, samplerState: samplerState);
            x += 96f;

            for (float r = 0.1f; r < Math.PI / 2f; r += 0.2f) {
                ir.Draw(TestTexture, x, y, sourceRect, rotation: r, samplerState: samplerState);

                x += 64f;
            }
        }
コード例 #13
0
ファイル: Message.cs プロジェクト: kg/rlms2013
        public void Draw(Frame frame, ref ImperativeRenderer renderer)
        {
            if (HideWhenPaused && Game.Paused)
                return;

            int layerOffset = 0;
            var t = (float)Time.Seconds - OpenedWhen;
            float opacity;

            if (t <= FadeInTime) {
                opacity = MathHelper.Lerp(0.0f, 1.0f, t / FadeInTime);
            } else if (t <= FadeInTime + HoldDuration) {
                opacity = 1.0f;
                layerOffset = 2;
            } else {
                if ((Style & MessageStyle.AutoClose) == MessageStyle.AutoClose) {
                    opacity = MathHelper.Lerp(1.0f, 0.0f, (t - (FadeInTime + HoldDuration)) / FadeOutTime);
                } else {
                    opacity = 1.0f;
                    layerOffset = 2;
                }
            }

            var size = Game.UIText.MeasureString(Text);

            var clippedSize = new Vector2(size.X, size.Y);
            if (clippedSize.X > 1000)
                clippedSize.X = 1000;

            var tl = new Vector2(
                (Game.ViewportWidth - clippedSize.X),
                (Game.ViewportHeight - clippedSize.Y)
            ) * Alignment.GetValueOrDefault(new Vector2(0.5f, 0.5f));
            var br = tl + clippedSize;
            var border = BorderSize;

            var colorInner = new Color(0.0f, 0.0f, 0.0f, BackgroundOpacity * opacity);
            var colorOuter = new Color(0.0f, 0.0f, 0.0f, 0.0f);

            renderer.FillRectangle(new Bounds(tl, br), colorInner);
            renderer.Layer += 1;
            renderer.DrawString(Game.UIText, Text, tl);
        }
コード例 #14
0
ファイル: Entity.cs プロジェクト: kg/rlms2013
 public abstract void Draw(ref ImperativeRenderer renderer);
コード例 #15
0
ファイル: Exploration.cs プロジェクト: kg/rlms2013
            public void Draw(ref ImperativeRenderer renderer)
            {
                if (Game.InputControls.MouseLocation.HasValue) {
                    var hotspot = State.HitTest(Game.InputControls.MouseLocation.Value).LastOrDefault();
                    if (hotspot == null)
                        return;

                    renderer.FillRectangle(hotspot.Bounds, Color.White * 0.1f);

                    var textLayout = Game.UIText.LayoutString(hotspot.ToString(), null);
                    var offset = ((hotspot.Bounds.Size - textLayout.Size) * 0.5f) + hotspot.Bounds.TopLeft;
                    offset.X = (float)Math.Floor(offset.X);
                    offset.Y = (float)Math.Floor(offset.Y);

                    renderer.DrawMultiple(textLayout, offset + Vector2.One, multiplyColor: Color.Black, sortKey: 0);
                    renderer.DrawMultiple(textLayout, offset, sortKey: 1);
                }
            }