Пример #1
0
        private void DrawOffscreen(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            Vector2i textSize = RB.PrintMeasure(mText);

            RB.Offscreen(2);
            RB.Clear(new Color32(0, 0, 0, 0));

            RB.DrawNineSlice(new Rect2i(0, 0, textSize.width + 12, textSize.height + 12), new Rect2i(80, 0, 8, 8), new Rect2i(88, 0, 8, 8), new Rect2i(96, 0, 16, 16));

            RB.Print(new Vector2i(6, 6), DemoUtil.IndexToRGB(23), mText);

            RB.Onscreen();
            RB.SpriteSheetSet(2);
            RB.DrawCopy(new Rect2i(0, 0, textSize.width + 12, textSize.height + 12), new Rect2i(x, y + 165, textSize.width + 12, textSize.height + 12), new Vector2i((textSize.width + 12) / 2, (textSize.height + 12) / 2), RB.Ticks);
            RB.SpriteSheetSet(0);

            mFormatStr.Set("@C// Draw to offscreen surface and copy to screen\n");
            mFormatStr.Append("@MVector2i @Nsize = @[email protected](textStr);\n");
            mFormatStr.Append("@[email protected](0);\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N, size.width + @L12@N, size.height + @L12@N),\n");
            mFormatStr.Append("  @Knew @MRect2i@N(@L80@N, @L0@N, @L8@N, @L8@N), @Knew @MRect2i@N(@L88@N, @L0@N, @L8@N, @L8@N),\n");
            mFormatStr.Append("  @Knew @MRect2i@N(@L96@N, @L0@N, @L16@N, @L16@N));\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L4@N, @L4@N), @I22@N, textStr);\n");
            mFormatStr.Append("@[email protected]();\n");
            mFormatStr.Append("@[email protected](0, \n");
            mFormatStr.Append("  @Knew@M Rect2i@N(@L0@N, @L0@N, size.width + @L7@N, size.height + @L8@N),\n");
            mFormatStr.Append("  @Knew@M Rect2i@N(@L").Append(x).Append("@N, @L").Append(y + 165).Append("@N, size.width + @L8@N, size.height + @L8@N),\n");
            mFormatStr.Append("  @Knew@M Vector2i@N(size.width / @L2@N, size.height / @L2@N), @L").Append(RB.Ticks % 360).Append("@N);\n");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Пример #2
0
        /// <summary>
        /// Render
        /// </summary>
        public void Render()
        {
            RB.DrawNineSlice(Rect, mNSFrame[FlashFrame]);

            if (mLaserOffset < 1.0f)
            {
                Vector2i offset = Vector2i.zero;
                offset.x = (int)(16 * mLaserOffset);
                offset.y = (int)(8 * mLaserOffset);

                byte prevAlpha = RB.AlphaGet();

                RB.AlphaSet((byte)((1 - mLaserOffset) * prevAlpha));
                RB.DrawCopy(new Rect2i(120, 10, 7, 10), new Rect2i(Rect.x - 3 - offset.x, Rect.y - 2 - offset.y, 7, 10));
                RB.DrawCopy(new Rect2i(120, 10, 7, 10), new Rect2i(Rect.x + Rect.width - 4 + offset.x, Rect.y - 2 - offset.y, 7, 10));
                RB.AlphaSet(prevAlpha);
            }
        }
Пример #3
0
        private void DrawTMX(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.SpriteSheetSet(0);

            mFormatStr.Set("@C// Load sprite packs at runtime just like any other spritesheet!\n");
            mFormatStr.Append("@[email protected](@L0@N, @S\"DemoReel/DemoSpritePack\"@N, @Knew@N @MVector2i@N(@L16@N, @L16@N));\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Now you can draw sprites using their sprite path and name, there is\n");
            mFormatStr.Append("@C// no need to specify source rectangle, RetroBlit sprite packing\n");
            mFormatStr.Append("@C// creates an internal lookup table that takes care of that for you!\n");

            var outputFrameRect = new Rect2i(x + 130, y + 60, 20, 20);

            DemoUtil.DrawOutputFrame(outputFrameRect, -1, 21, 22);

            if (RB.Ticks % 40 < 20)
            {
                mFormatStr.Append("@[email protected](@S\"Characters/Hero1\"@N, @Knew@N @MVector2i@N(@L32@N, @L48@N));\n");
                RB.DrawSprite("Characters/Hero1", new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 2));
            }
            else
            {
                mFormatStr.Append("@[email protected](@S\"Characters/Hero2\"@N, @Knew@N @MVector2i@N(@L32@N, @L48@N));\n");
                RB.DrawSprite("Characters/Hero2", new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 2));
            }

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            y += 90;

            mFormatStr.Set("@C// You can also use sprite packs with tile maps\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L0@N, @L0@N), @S\"Terrain/GrassTopRight\"@N, @[email protected]_H);\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L1@N, @L0@N), @S\"Terrain/GrassTop\"@N);\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L2@N, @L0@N), @S\"Terrain/GrassTop\"@N);\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L3@N, @L0@N), @S\"Terrain/GrassTopRight\"@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L0@N, @L1@N), @S\"Terrain/DirtSide\"@N, @[email protected]_H);\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L1@N, @L1@N), @S\"Terrain/DirtCenter\"@N);\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L2@N, @L1@N), @S\"Terrain/DirtCenter\"@N);\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew@N @MVector2i@N(@L3@N, @L1@N), @S\"Terrain/DirtSide\"@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected](0);");
            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            RB.MapSpriteSet(0, new Vector2i(0, 0), mSpriteGrassTopRight, RB.FLIP_H);
            RB.MapSpriteSet(0, new Vector2i(1, 0), mSpriteGrassTop);
            RB.MapSpriteSet(0, new Vector2i(2, 0), mSpriteGrassTop);
            RB.MapSpriteSet(0, new Vector2i(3, 0), mSpriteGrassTopRight);

            RB.MapSpriteSet(0, new Vector2i(0, 1), mSpriteDirtSide, RB.FLIP_H);
            RB.MapSpriteSet(0, new Vector2i(1, 1), mSpriteDirtCenter);
            RB.MapSpriteSet(0, new Vector2i(2, 1), mSpriteDirtCenter);
            RB.MapSpriteSet(0, new Vector2i(3, 1), mSpriteDirtSide);

            outputFrameRect = new Rect2i(x + 105, y + 95, (16 * 4) + 4, (16 * 2) + 4);
            DemoUtil.DrawOutputFrame(outputFrameRect, -1, 21, 22);

            RB.DrawMapLayer(0, new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 4));

            y += 140;

            mFormatStr.Set("@C// Sometimes it can be useful to get the sprite source rectangle\n");
            mFormatStr.Append("@Kvar@N sprite = @[email protected](@S\"Terrain/Water\"@N);\n");
            mFormatStr.Append("@Kvar@N sourceRect = sprite.SourceRect;\n");
            mFormatStr.Append("sourceRect.x += @L").Append((int)((RB.Ticks / 2) % 16)).Append("@N;\n");
            mFormatStr.Append("@[email protected](sourceRect, @Knew@N @MVector2i@N(@L32@N, @L48@N));\n");
            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            outputFrameRect = new Rect2i(x + 130, y + 44, 16 + 4, 16 + 4);
            DemoUtil.DrawOutputFrame(outputFrameRect, -1, 21, 22);

            var sprite     = RB.PackedSpriteGet("Terrain/Water");
            var sourceRect = sprite.SourceRect;

            sourceRect.x    += (int)((RB.Ticks / 2) % 16);
            sourceRect.width = 16;
            RB.DrawCopy(sourceRect, new Vector2i(outputFrameRect.x + 2, outputFrameRect.y + 2));

            y += 72;

            mFormatStr.Set("@C// You can also use sprite packs for custom fonts, nine-slice images,\n");
            mFormatStr.Append("@C// and when loading map layers from TMX files!\n");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            y += 20;
            mFormatStr.Set("@w444");

            int count = mCounter;
            int ms    = count % 60;

            count /= 60;
            int s = count % 60;

            count /= 60;
            int m = count;

            mFormatStr.Append(m, 2).Append(':').Append(s, 2).Append(':').Append(ms, 2);

            mCounter++;
            if (mCounter >= 60 * 60 * 60)
            {
                mCounter = 0;
            }

            RB.Print(0, new Vector2i(x + 15, y + 8), Color.white, mFormatStr);

            int xGrow = (int)(Mathf.Sin(RB.Ticks / 40.0f) * 20.0f) + 20 + 20;
            int yGrow = (int)(Mathf.Sin(RB.Ticks / 20.0f) * 18.0f) + 18 + 16;

            RB.DrawNineSlice(new Rect2i(x + 130 - (xGrow / 2), y + 18 - (yGrow / 2), xGrow, yGrow), mNineSlice);

            RB.DrawMapLayer(1, new Vector2i(x + 190, y - 1));
        }