Example #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));
        }
Example #2
0
        private void DrawClip(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));

            mDialogStr.Set("You there!\nThat's a nice\ngolden sword,\nand dragon\nhide armor!\nYou look like\nyou could use a\nfew coppers,\nhow about you\nclean out\nthe @dbab7710@- rats in\nmy basement?");

            var size     = (int)(Mathf.Sin(RB.Ticks / 20.0f) * 22) * 2;
            var textRect = new Rect2i(32 - (size / 2), 45, 80 + size, 128);

            DrawTextFrame(textRect, null);
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER | RB.TEXT_OVERFLOW_CLIP, mDialogStr);

            textRect = new Rect2i(32 - (size / 2) + 140, 45, 80 + size, 128);
            DrawTextFrame(textRect, null);
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER | RB.TEXT_OVERFLOW_WRAP | RB.TEXT_OVERFLOW_CLIP, mDialogStr);

            textRect = new Rect2i(32 - (size / 2) + 70, 180, 80 + size, 128);
            DrawTextFrame(textRect, null);
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER | RB.TEXT_OVERFLOW_WRAP, mDialogStr);

            mFormatStr.Set("@C// Clip and wrap text in a text rectangle\n").Append("@Kint@N center = @[email protected]_H_CENTER | @[email protected]_V_CENTER;\n");
            mFormatStr.Append("@[email protected](@Knew@N Rect2i(@L20@N, @L20@N, @L").Append(80 + size).Append("@N, @L128@N),\n   center | @[email protected]_OVERFLOW_CLIP, myText);\n");
            mFormatStr.Append("@[email protected](@Knew@N Rect2i(@L160@N, @L20@N, @L").Append(80 + size).Append("@N, @L128@N),\n   center | @[email protected]_OVERFLOW_WRAP | @[email protected]_OVERFLOW_CLIP, myText);\n");
            mFormatStr.Append("@[email protected](@Knew@N Rect2i(@L90@N, @L155@N, @L").Append(80 + size).Append("@N, @L128@N),\n   center | @[email protected]_OVERFLOW_WRAP, myText);\n");

            RB.CameraReset();

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #3
0
        private void DrawCode(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));

            mFormatStr.Set("@C// RetroBlit lets you draw pixel buffers!\n");
            mFormatStr.Append("@MColor32@N[] pixelBuffer = @Knew @MColor32@N[@L").Append(mFireSize.width).Append("@N * @L");
            mFormatStr.Append(mFireSize.height).Append("@N];\n");
            mFormatStr.Append("@C/* ... fill pixel buffer with pixel colors ... */\n\n");

            mFormatStr.Append("@C// Draw pixel buffer at 1:1 scale, anywhere on the screen\n");
            mFormatStr.Append("@[email protected](@NpixelBuffer, @Knew @MVector2i@N(@L").Append(mFireSize.width).Append("@N, @L");
            mFormatStr.Append(mFireSize.height).Append("@N), @Knew @MVector2i@N(@L").Append(mFirePos.x).Append("@N, @L").Append(mFirePos.y);
            mFormatStr.Append("@N));\n\n");

            mFormatStr.Append("@C// Or rotate and scale it just like a sprite!\n");
            mFormatStr.Append("@[email protected](@NpixelBuffer, @Knew @MVector2i@N(@L").Append(mFireSize.width).Append("@N, @L");
            mFormatStr.Append(mFireSize.height).Append("@N), @Knew @MRect2i@N(@L").Append(mFireRect.x).Append("@N, @L").Append(mFireRect.y);
            mFormatStr.Append("@N, @L").Append(mFireRect.width).Append("@N, @L").Append(mFireRect.height).Append("@N), ");
            mFormatStr.Append("@Knew @MVector2i@N(@L").Append(mFireSize.width / 2).Append("@N, @L").Append(mFireSize.height / 2).Append("@N), ");
            mFormatStr.Append("@L").Append(mRotation, 2).Append("@N);");

            RB.CameraReset();

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #4
0
        private void DrawSystemFont(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));

            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 49, 6), -1, mOutputFrame, mOutputBackground);

            int c1 = ((int)RB.Ticks / 10) % 32;
            int c2 = (((int)RB.Ticks / 10) + 10) % 32;
            int c3 = (((int)RB.Ticks / 10) + 20) % 32;

            var color1 = DemoUtil.IndexToRGB(c1);
            var color2 = DemoUtil.IndexToRGB(c2);
            var color3 = DemoUtil.IndexToRGB(c3);

            mFormatStr.Set("Hello @");
            mFormatStr.Append(color1.r, 2, FastString.FORMAT_HEX_CAPS).Append(color1.g, 2, FastString.FORMAT_HEX_CAPS).Append(color1.b, 2, FastString.FORMAT_HEX_CAPS).Append("fr@");
            mFormatStr.Append(color2.r, 2, FastString.FORMAT_HEX_CAPS).Append(color2.g, 2, FastString.FORMAT_HEX_CAPS).Append(color2.b, 2, FastString.FORMAT_HEX_CAPS).Append("ie@");
            mFormatStr.Append(color3.r, 2, FastString.FORMAT_HEX_CAPS).Append(color3.g, 2, FastString.FORMAT_HEX_CAPS).Append(color3.b, 2, FastString.FORMAT_HEX_CAPS).Append("nd");

            RB.Print(new Vector2i(0, 0), DemoUtil.IndexToRGB(6), mFormatStr);

            RB.CameraReset();

            mFormatStr.Set("@C// Print text with default system font, with inline color support\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L0@N, @L0@N), @I06@N,\n").Append("   @S\"Hello @s@@");
            mFormatStr.Append(color1.r, 2, FastString.FORMAT_HEX_CAPS).Append(color1.g, 2, FastString.FORMAT_HEX_CAPS).Append(color1.b, 2, FastString.FORMAT_HEX_CAPS).Append("@Sfr@s@@");
            mFormatStr.Append(color2.r, 2, FastString.FORMAT_HEX_CAPS).Append(color2.g, 2, FastString.FORMAT_HEX_CAPS).Append(color2.b, 2, FastString.FORMAT_HEX_CAPS).Append("@Sie@s@@");
            mFormatStr.Append(color3.r, 2, FastString.FORMAT_HEX_CAPS).Append(color3.g, 2, FastString.FORMAT_HEX_CAPS).Append(color3.b, 2, FastString.FORMAT_HEX_CAPS).Append("@Snd\"@N);");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #5
0
        private void DrawCode(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));

            mFormatStr.Set("@C// RetroBlit assets can also be loaded asynchronously from Resources, WWW, and Addressable Assets (with Unity AA package installed)!@N\n");
            mFormatStr.Append("@MSpriteSheetAsset@N spriteSheet = @Knew@N SpriteSheetAsset();\n");
            mFormatStr.Append("@MAudioAsset@N audio = @Knew@N AudioAsset();\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@Kvoid @MInitialize@N() {\n");
            mFormatStr.Append("    spriteSheet.Load(@S\"https://www.retroblit.com/superflagrun.png\"@N, @MRB@N.@MAssetSource@N.@LWWW@N);\n");
            mFormatStr.Append("    audio.Load(@S\"ding\"@N, @MRB@N.@MAssetSource@N.@LAddressableAssets@N);\n");
            mFormatStr.Append("};\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@Kvoid@N Update() {\n");
            mFormatStr.Append("    @Kif@N (audio.status == @MRB@N.@MAssetStatus@N.@LReady@N) {\n");
            mFormatStr.Append("        @[email protected](audio);\n");
            mFormatStr.Append("    }\n");
            mFormatStr.Append("};\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@Kvoid@N Render() {\n");
            mFormatStr.Append("    @Kif@N (spriteSheet.status == @MRB@N.@MAssetStatus@N.@LReady@N) {\n");
            mFormatStr.Append("        @[email protected](spriteSheet);\n");
            mFormatStr.Append("        @[email protected](@L0@N, @Knew@N Vector2i(@L100@N, @L50@N));\n");
            mFormatStr.Append("    }\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("    @Kif@N (spriteSheet.status != @MRB@N.@MAssetStatus@N.@LReady@N) DrawSpriteSheetProgress(spriteSheet.progress);\n");
            mFormatStr.Append("    @Kif@N (audio.status != @MRB@N.@MAssetStatus@N.@LReady@N) DrawAudioProgress(audio.progress);\n");
            mFormatStr.Append("};\n");

            RB.CameraReset();

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #6
0
        private void DrawTint(int x, int y, int spriteIndex)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 50));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 64, 16), -1, mOutputFrame, mOutputBackground);

            RB.TintColorSet(Color.white);
            RB.DrawSprite(spriteIndex, new Vector2i(0, 0));
            RB.TintColorSet(DemoUtil.IndexToRGB(12));
            RB.DrawSprite(spriteIndex, new Vector2i(24, 0));
            RB.TintColorSet(DemoUtil.IndexToRGB((int)(RB.Ticks / 10) % 32));
            RB.DrawSprite(spriteIndex, new Vector2i(48, 0));
            RB.TintColorSet(Color.white);

            RB.CameraReset();

            mFormatStr.Set("@C// Set tint color for drawing (RGB Mode only)\n");
            mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MVector2i@N(@L0@N, @L0@N));\n");
            mFormatStr.Append("@[email protected](@I12);\n").Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MVector2i@N(@L24@N, @L0@N));\n");
            mFormatStr.Append("@[email protected](@I").Append((RB.Ticks / 10) % 32, 2).Append(");\n");
            mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MVector2i(@L48@N, @L0@N));");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #7
0
        private void DrawNoisePad(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y));

            mFormatStr.Set("@C// Load sounds and play them\n");
            mFormatStr.Append("@NsoundCoin.Load(@S\"Demos/Demo/Coin\"@N);\n");
            mFormatStr.Append("@NsoundExplosion.Load(@S\"Demos/Demo/Explosion\"@N);\n");
            mFormatStr.Append("@NsoundJump.Load(@S\"Demos/Demo/Jump\"@N);\n");
            mFormatStr.Append("@NsoundLaser.Load(@S\"Demos/Demo/Laser\"@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@Kif@N (@[email protected](@[email protected]) {\n");
            mFormatStr.Append("   @[email protected](soundCoin);\n");
            mFormatStr.Append("} @Kelse if@N (@[email protected](@[email protected]) {\n");
            mFormatStr.Append("   @[email protected](soundExplosion);\n");
            mFormatStr.Append("} @Kelse if@N (@[email protected](@[email protected]) {\n");
            mFormatStr.Append("   @[email protected](soundJump);\n");
            mFormatStr.Append("} @Kelse if@N (@[email protected](@[email protected]) {\n");
            mFormatStr.Append("   @[email protected](soundLaser);\n");
            mFormatStr.Append("}");

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

            RB.CameraSet(new Vector2i(-x, -y - 123));
            for (int i = 0; i < mEffectButtons.Length; i++)
            {
                mEffectButtons[i].Render();
            }

            RB.CameraReset();
        }
Example #8
0
        private void DrawSprite(int x, int y, int spriteIndex)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 17));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 16, 16), -1, mOutputFrame, mOutputBackground);

            mFormatStr.Clear();

            if (RB.Ticks % 200 < 100)
            {
                mFormatStr.Append("@C// Draw sprite from sprite sheet by its index\n");
                mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MVector2i@N(@L0@N, @L0@N));");
                RB.DrawSprite(spriteIndex, new Vector2i(0, 0));
            }
            else
            {
                mFormatStr.Append("@C// Draw sprite from sprite sheet by its index\n");
                mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MVector2i@N(@L0@N, @L0@N), @[email protected]_H );");
                RB.DrawSprite(spriteIndex, new Vector2i(0, 0), RB.FLIP_H);
            }

            RB.CameraReset();

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #9
0
        private void DrawLines(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 58));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 260, 34), -1, mOutputFrame, mOutputBackground);

            Vector2i lineCenter = new Vector2i(130, 33);

            for (int i = 0; i < mLinePoint.Length; i++)
            {
                mLinePoint[i].x = (int)(Mathf.Cos((i / (float)mLinePoint.Length * Mathf.PI) + Mathf.PI) * 128);
                mLinePoint[i].y = -(int)(Mathf.Sin(i / ((float)mLinePoint.Length - 1) * Mathf.PI) * 34);
                mLinePoint[i]  += lineCenter;
            }

            for (int i = 0; i < mLinePoint.Length; i++)
            {
                RB.DrawLine(lineCenter, mLinePoint[i], DemoUtil.IndexToRGB((i + (((int)RB.Ticks / 10) % 32)) % 32));
            }

            RB.CameraReset();

            mFormatStr.Set("@C// Draw lines\n");
            mFormatStr.Append("@Kfor @N(@Kint@N i = @L0@N; i < @L32@N; i++) {\n");
            mFormatStr.Append("    @MVector2i@N p = @Knew @MVector2i@N(\n");
            mFormatStr.Append("        (@Kint@N)(@[email protected](i / @L38.0f@N * @[email protected] + @[email protected]) * @L128@N, \n");
            mFormatStr.Append("        @L-@N(@Kint@N)(@[email protected](i / @L37.0f@N * @[email protected]) * @L34h@N));\n");
            mFormatStr.Append("    @[email protected](@Knew @MVector2i@N(@L").Append(lineCenter.x).Append("@N, @L").Append(lineCenter.y).Append("@N), p, MyRGBColor(i + @L").Append(((int)RB.Ticks / 10) % 32).Append("@N) % @L32@N));\n};");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #10
0
        private void DrawCode(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            mFormatStr.Set("@C// Load infinite TMX maps chunk by chunk to create maps of any size!@N\n");
            mFormatStr.Append("@Kvar@N chunkPixelSize = @Knew@N @MVector2i@N(@[email protected] * @[email protected](@L0@N).width, @[email protected] * @[email protected](@L0@N).height);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Figure out which map chunk is in the top left corner of the camera view@N\n");
            mFormatStr.Append("@Kvar@N newTopLeftChunk = @Knew@N @MVector2i@N(mCameraPos.x / chunkPixelSize.width, mCameraPos.y / chunkPixelSize.height);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Check if the camera moved enough so that the top left chunk has changed, if so then we need to shift the map and load a new chunk.@N\n");
            mFormatStr.Append("@Kif@N (newTopLeftChunk != mTopLeftChunk) {\n");
            mFormatStr.Append("    @[email protected](@L0@N, mTopLeftChunk - newTopLeftChunk);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("    @C// After shifting loop through all potentially visible chunks and load any that are now empty.@N\n");
            mFormatStr.Append("    @Kfor@N (@Kint@N cx = @L0@N; cx <= @[email protected] / chunkPixelSize.width + @L1@N; cx++) {\n");
            mFormatStr.Append("        @Kvar@N chunkPos = @Knew@N @MVector2i@N(cx * RB.MapChunkSize.x, cy * RB.MapChunkSize.y);\n");
            mFormatStr.Append("        @Kvar@N mapPos = @Knew@N @MVector2i@N(newTopLeftChunk.x * RB.MapChunkSize.x, newTopLeftChunk.y * RB.MapChunkSize.y) + chunkPos;\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("        @Kif@N (@[email protected](@L0@N, chunkPos)) {\n");
            mFormatStr.Append("            @[email protected](mMap, @S\"Terrain\"@N, @L0@N, mapPos, chunkPos);\n");
            mFormatStr.Append("        }\n");
            mFormatStr.Append("    }\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("    mTopLeftChunk = newTopLeftChunk;\n");
            mFormatStr.Append("}\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected](@Knew@N @MVector2i@N(mCameraPos.x % chunkPixelSize.width, mCameraPos.y % chunkPixelSize.height));\n");
            mFormatStr.Append("@[email protected](@L0@N);\n");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #11
0
        private void DrawTMX()
        {
            var demo = (DemoReel)RB.Game;

            int    spriteFrame   = (RB.Ticks % 40) > 20 ? 1 : 0;
            Rect2i clipRect      = new Rect2i(0, 0, 0, 0);
            int    cameraYOffset = 0;
            int    cameraXOffset = 0;
            int    cameraYRange  = 16;

            if (mStyle == RB.PixelStyle.Wide)
            {
                clipRect = new Rect2i((RB.DisplaySize.width / 2) - 100, RB.DisplaySize.height - 220, 200, 200);
            }
            else if (mStyle == RB.PixelStyle.Tall)
            {
                clipRect      = new Rect2i((RB.DisplaySize.width / 2) - 200, RB.DisplaySize.height - 110, 400, 100);
                cameraYOffset = 150;
                cameraXOffset = -120;
                cameraYRange  = 8;
            }

            if (mMap != null)
            {
                int      scrollPos = -(int)RB.Ticks % (mMapSize.width * RB.SpriteSize().width);
                Vector2i cameraPos = new Vector2i((int)((Mathf.Sin(RB.Ticks / 100.0f) * 420) + 450 + cameraXOffset), (int)((Mathf.Sin(RB.Ticks / 10.0f) * cameraYRange) + cameraYOffset));

                RB.ClipSet(clipRect);
                RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22));

                RB.CameraSet(cameraPos);
                RB.DrawMapLayer(0, new Vector2i(scrollPos, 0));
                RB.DrawMapLayer(0, new Vector2i(scrollPos + (mMapSize.width * RB.SpriteSize().width), 0));
                RB.DrawMapLayer(1);
                RB.DrawMapLayer(2);
                RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16));
                RB.DrawSprite(RB.SpriteIndex(6, 10) + spriteFrame, new Vector2i(67 * 16, 14 * 16));
                RB.CameraReset();
            }
            else
            {
                RB.Print(new Vector2i(clipRect.x + 2, clipRect.y + 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map\nDemos/DemoReel/Tilemap.tmx in Unity");
            }

            RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21));

            RB.ClipReset();

            mFormatStr.Set("@C// Use ").Append(mStyle == RB.PixelStyle.Wide ? "wide" : "tall").Append(" pixel format\n");
            mFormatStr.Append("@Kpublic @MHardwareSettings @NQueryHardware() {\n");
            mFormatStr.Append("   @Kvar @Nhw = @Knew @MHardwareSettings@N();\n");
            mFormatStr.Append("   @Nhw.DisplaySize = @Knew @MVector2i@N(@L").Append(RB.DisplaySize.width).Append("@N, @L").Append(RB.DisplaySize.height).Append("@N);\n");
            mFormatStr.Append("   @Nhw.PixelStyle = @KRetroBlit@N.@EPixelStyle@N.").Append(mStyle == RB.PixelStyle.Wide ? "Wide" : "Tall").Append(";\n");
            mFormatStr.Append("   @Kreturn @Nhw;\n");
            mFormatStr.Append("}");

            RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #12
0
        private void DrawDesc(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            mFormatStr.Set(mDesc);
            DemoUtil.HighlightCode(mFormatStr, mFinalStr);

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), mFinalStr);
        }
        private void DrawTMX(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            Rect2i   clipRect    = new Rect2i(x + 16, y + 142, 310, 207);
            Vector2i cameraPos   = new Vector2i((int)(Mathf.Sin(RB.Ticks / 100.0f) * 450) + 200, (int)Mathf.Sin(RB.Ticks / 10.0f) * 16);
            int      spriteFrame = (RB.Ticks % 40) > 20 ? 1 : 0;

            if (mMap != null && mMap.status == RB.AssetStatus.Ready)
            {
                int scrollPos = -(int)RB.Ticks % (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width);

                RB.ClipSet(clipRect);
                RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22));

                RB.CameraSet(cameraPos);

                RB.DrawMapLayer(1, new Vector2i(scrollPos, 0));
                RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSheetGet().grid.cellSize.width), 0));
                RB.DrawMapLayer(2);
                RB.DrawMapLayer(3);
                RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16));
                RB.DrawSprite(RB.SpriteIndex(6, 10) + spriteFrame, new Vector2i(67 * 16, 14 * 16));
            }
            else
            {
                RB.CameraReset();
                RB.ClipReset();
                RB.Print(new Vector2i(x + 18, y + 144), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity");
            }

            RB.CameraReset();
            RB.ClipReset();
            RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21));

            mMap.Load("Demos/DemoReel/Tilemap");

            mFormatStr.Set("@C// Load a map from a TMX file\n");
            mFormatStr.Append("@NmyTMXMap.Load(@S\"Demos/Demo/Tilemap\"@N);\n");
            mFormatStr.Append("@NmyTMXMap.LoadLayer(@S\"Clouds\"@N, @L1@N);\n");
            mFormatStr.Append("@NmyTMXMap.LoadLayer(@S\"Decoration\"@N, @L2@N);\n");
            mFormatStr.Append("@NmyTMXMap.LoadLayer(@S\"Terrain\"@N, @L3@N);\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N));\n");
            mFormatStr.Append("@[email protected](@Knew@N @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N), @I22);\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L").Append(cameraPos.x).Append("@N, @L").Append(cameraPos.y).Append("@N));\n");
            mFormatStr.Append("@Kint@N pos = @L").Append(-(int)RB.Ticks).Append("@N % (myMap.size.width * @[email protected]);\n");
            mFormatStr.Append("@[email protected](@L1@N, @Knew @MVector2i@N(pos, @L0@N));\n");
            mFormatStr.Append("@[email protected](@L1@N, @Knew @MVector2i@N(pos + (myMap.size.width * @[email protected])), @L0@N));\n");
            mFormatStr.Append("@[email protected](@L2@N);\n");
            mFormatStr.Append("@[email protected](@L3@N);\n");
            mFormatStr.Append("@[email protected](@L").Append(0 + spriteFrame).Append("@N, @Knew@N @MVector2i@N(@L").Append(13 * 16).Append("@N, @L").Append(16 * 16).Append("@N));\n");
            mFormatStr.Append("@[email protected](@L").Append(RB.SpriteIndex(6, 10) + spriteFrame).Append("@N, @Knew @MVector2i@N(@L").Append(67 * 16).Append("@N, @L").Append(14 * 16).Append("@N));\n");
            mFormatStr.Append("@[email protected]();\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N), @I21);\n");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            var demo = (DemoReel)RB.Game;

            RB.Clear(DemoUtil.IndexToRGB(22));

            int spriteFrame = ((int)RB.Ticks % 40) > 20 ? 1 : 0;

            if (mMap != null)
            {
                RB.DrawMapLayer(0);
                RB.DrawMapLayer(1);
            }

            RB.EffectSet(RB.Effect.Noise, 0.15f);
            RB.EffectSet(RB.Effect.Scanlines, 1.0f);
            RB.EffectSet(RB.Effect.Desaturation, (Mathf.Sin(RB.Ticks / 50.0f) * 0.5f) + 0.5f);

            RB.EffectApplyNow();
            RB.EffectReset();

            if (mMap != null)
            {
                RB.DrawSprite(0 + spriteFrame, new Vector2i(13 * 16, 16 * 16));
            }
            else
            {
                RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity");
            }

            mFormatStr.Set("@C// Specify when post-processing effects should be applied\n");
            mFormatStr.Append("@[email protected](@L0@N);\n");
            mFormatStr.Append("@[email protected](@L1@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected](@MRB@N.@[email protected], @L0.15f@N);\n");
            mFormatStr.Append("@[email protected](@MRB@N.@[email protected], @L1.0f@N);\n");
            mFormatStr.Append("@[email protected](@MRB@N.@[email protected], @L").Append((Mathf.Sin(RB.Ticks / 50.0f) * 0.5f) + 0.5f, 2).Append("f@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected]();\n");
            mFormatStr.Append("@[email protected]();\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected](@L").Append(0 + spriteFrame).Append("@N, @Knew@N Vector2i(@L").Append(13 * 16).Append("@N, @L").Append(16 * 16).Append("@N));");

            var size = RB.PrintMeasure(DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            size.x += 4;
            size.y += 4;

            var rect = new Rect2i((RB.DisplaySize.width / 2) - (size.x / 2), (RB.DisplaySize.height / 2) - (size.y / 2), size.x, size.y);

            rect.y -= 64;

            RB.DrawRectFill(rect, DemoUtil.IndexToRGB(1));
            RB.DrawRect(rect, DemoUtil.IndexToRGB(4));
            RB.Print(new Vector2i(rect.x + 2, rect.y + 2), DemoUtil.IndexToRGB(0), mFinalStr);
        }
Example #15
0
        private void DrawCode(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            mFormatStr.Set("@C// Interpolate between integers, floats, colors, vectors, and more using RetroBlit easing functions!\n");
            mFormatStr.Append("@Kint@N num = @[email protected](@MEase@N.@[email protected], @L10@N, @L20@N, @L0.5f@N);\n");
            mFormatStr.Append("@KColor@N color = @[email protected](@MEase@N.@[email protected], @[email protected], @[email protected], @L0.75f@N);\n");
            mFormatStr.Append("@KVector2i@N vec = @[email protected](@MEase@N.@[email protected], @Knew@N @MVector2i@N(@L0@N, @L0@N), @Knew@N @MVector2i@N(@L-5@N, @L-8@N), @L0.33f@N);\n");
            mFormatStr.Append("@KRect2i@N rect = @[email protected](@MEase@N.@[email protected], @Knew@N @MRect2i@N(@L5@N, @L5@N, @L10@N, @L10@N), @Knew@N @MRect2i@N(@L0@N, @L0@N, @L5@N, @L5@N), @L0.1f@N);\n");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #16
0
        private void DrawAlign(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));

            mDialogStr.Set("\u30B3\u30F3\u30CB\u30C1\u30EF\n@dbab77RetroBlit@- supports\nunicode fonts!");

            var textRect = new Rect2i(2, 12, 96, 48);

            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_LEFT | @[email protected]_V_TOP"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_LEFT | RB.ALIGN_V_TOP, mDialogStr);

            textRect = new Rect2i(112, 12, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_CENTER | @[email protected]_V_TOP"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_TOP, mDialogStr);

            textRect = new Rect2i(222, 12, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_RIGHT | @[email protected]_V_TOP"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_RIGHT | RB.ALIGN_V_TOP, mDialogStr);

            textRect = new Rect2i(2, 112, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_LEFT | @[email protected]_V_CENTER"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_LEFT | RB.ALIGN_V_CENTER, mDialogStr);

            textRect = new Rect2i(112, 112, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_CENTER | @[email protected]_V_CENTER"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, mDialogStr);

            textRect = new Rect2i(222, 112, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_RIGHT | @[email protected]_V_CENTER"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_RIGHT | RB.ALIGN_V_CENTER, mDialogStr);

            textRect = new Rect2i(2, 212, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_LEFT | @[email protected]_V_BOTTOM"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_LEFT | RB.ALIGN_V_BOTTOM, mDialogStr);

            textRect = new Rect2i(112, 212, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_CENTER | @[email protected]_V_BOTTOM"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_CENTER | RB.ALIGN_V_BOTTOM, mDialogStr);

            textRect = new Rect2i(222, 212, 96, 48);
            DrawTextFrame(textRect, DemoUtil.HighlightCode(mFormatStr.Set("alignFlags = \n@[email protected]_H_RIGHT | @[email protected]_V_BOTTOM"), mFinalStr));
            RB.Print(textRect, DemoUtil.IndexToRGB(4), RB.ALIGN_H_RIGHT | RB.ALIGN_V_BOTTOM, mDialogStr);

            mFormatStr.Set("@C// Print text within a text rectangle, with specific alignment\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L8@N, @L8@N, @L96@N, @L48@N), alignFlags,\n");
            mFormatStr.Append("   @S\"\u30B3\u30F3\u30CB\u30C1\u30EF\\n@@dbab77RetroBlit@@- supports\\nunicode fonts!\"@N);");

            RB.CameraReset();

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #17
0
        private void DrawCode(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), "Source code:");
            RB.DrawRectFill(new Rect2i(x, y + 10, 315, 270), DemoUtil.IndexToRGB(1));

            mFormatStr.Set(mMarkedUpCode);
            DemoUtil.HighlightCode(mFormatStr, mFinalStr);

            RB.Print(new Vector2i(x + 4, y + 14), DemoUtil.IndexToRGB(5), mFinalStr);
        }
Example #18
0
        private void DrawPiano(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y));

            mFormatStr.Set("@C// Play sound at specific volume and pitch\n");
            mFormatStr.Append("@NsoundC5Note.Load(@S\"Demos/Demo/C5Note\"@N);\n");
            mFormatStr.Append("@[email protected](soundC5Note, @L0.@L5f@N, @L1.@L2f@N);\n");

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

            RB.CameraSet(new Vector2i(-x, -y - 35));

            Rect2i pianoRect = mPianoRect;
            Rect2i holeRect  = pianoRect;

            pianoRect = pianoRect.Expand(8);
            holeRect  = holeRect.Expand(2);

            int cornerSize = 8;

            RB.DrawEllipseFill(new Vector2i(pianoRect.x + cornerSize, pianoRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3));
            RB.DrawEllipse(new Vector2i(pianoRect.x + cornerSize, pianoRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2));

            RB.DrawEllipseFill(new Vector2i(pianoRect.x + pianoRect.width - cornerSize - 1, pianoRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3));
            RB.DrawEllipse(new Vector2i(pianoRect.x + pianoRect.width - cornerSize - 1, pianoRect.y + cornerSize), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2));

            RB.DrawEllipseFill(new Vector2i(pianoRect.x + cornerSize, pianoRect.y + pianoRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3));
            RB.DrawEllipse(new Vector2i(pianoRect.x + cornerSize, pianoRect.y + pianoRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2));

            RB.DrawEllipseFill(new Vector2i(pianoRect.x + pianoRect.width - cornerSize - 1, pianoRect.y + pianoRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(3));
            RB.DrawEllipse(new Vector2i(pianoRect.x + pianoRect.width - cornerSize - 1, pianoRect.y + pianoRect.height - cornerSize - 1), new Vector2i(cornerSize, cornerSize), DemoUtil.IndexToRGB(2));

            RB.DrawRect(new Rect2i(pianoRect.x + cornerSize, pianoRect.y, pianoRect.width - (cornerSize * 2), pianoRect.height), DemoUtil.IndexToRGB(2));
            RB.DrawRectFill(new Rect2i(pianoRect.x + cornerSize, pianoRect.y + 1, pianoRect.width - (cornerSize * 2), pianoRect.height - 2), DemoUtil.IndexToRGB(3));

            RB.DrawRect(new Rect2i(pianoRect.x, pianoRect.y + cornerSize, cornerSize, pianoRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(2));
            RB.DrawRectFill(new Rect2i(pianoRect.x + 1, pianoRect.y + cornerSize, cornerSize - 1, pianoRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(3));

            RB.DrawRect(new Rect2i(pianoRect.x + pianoRect.width - cornerSize, pianoRect.y + cornerSize, cornerSize, pianoRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(2));
            RB.DrawRectFill(new Rect2i(pianoRect.x + pianoRect.width - cornerSize - 1, pianoRect.y + cornerSize, cornerSize, pianoRect.height - (cornerSize * 2)), DemoUtil.IndexToRGB(3));

            RB.DrawRectFill(holeRect, DemoUtil.IndexToRGB(2));

            for (int i = 0; i < mPianoButtons.Length; i++)
            {
                mPianoButtons[i].Render();
            }

            RB.CameraReset();
        }
Example #19
0
        private void DrawRotate(int x, int y, int spriteIndex)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 17));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 18, 18), -1, mOutputFrame, mOutputBackground);

            RB.DrawSprite(spriteIndex, new Vector2i(1, 1), new Vector2i(8, 8), (RB.Ticks * 4) % 360);

            RB.CameraReset();

            mFormatStr.Set("@C// Rotate sprites around pivot point\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i(@1@N, @L1@N), @Knew @MVector2i@N(@L8@N, @L8@N), @L").Append((RB.Ticks * 4) % 360).Append("@N);");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #20
0
        private void DrawCopy(int x, int y, int spriteIndex)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 17));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 16, 16), -1, mOutputFrame, mOutputBackground);

            int copySize = (int)((Mathf.Sin(RB.Ticks / 20.0f) * 8) + 9);

            RB.DrawCopy(new Rect2i(0, 0, copySize, copySize), new Vector2i(0, 0));

            RB.CameraReset();

            mFormatStr.Set("@C// Draw rectangular areas from sprite sheet\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i(@L0@N, @L0@N, @L").Append(copySize).Append("@N, @L").Append(copySize).Append("@N), @Knew @MVector2i@N(@L0@N, @L0@N));");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #21
0
        private void DrawFontEffects(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));

            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 136, 12), -1, mOutputFrame, mOutputBackground);

            mFormatStr.Set("@w243Wavy@w000 and @s1shaky!@s0. Why not @w243@s1both?");

            RB.Print(new Vector2i(0, 3), DemoUtil.IndexToRGB(6), mFormatStr);

            RB.CameraReset();

            mFormatStr.Set("@C// Apply wavy and shaky text effects!\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L0@N, @L0@N), @I06@N,\n").Append("   @S\"@s@@w243@SWavy@s@@w000@S and @s@@s1@Sshaky!@s@@s0@S. Why not @s@@w243@@s1@Sboth?\"").Append("@N);");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #22
0
        private void DrawPixels(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 41));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 256, 12), -1, mOutputFrame, mOutputBackground);

            for (int i = 0; i < 32; i++)
            {
                RB.DrawPixel(new Vector2i((int)(Mathf.Sin((RB.Ticks / 100.0f) + (i / 10.0f)) * 128) + 128, (int)(Mathf.Sin((RB.Ticks / 10.0f) + (i / 2.0f)) * 6) + 6), DemoUtil.IndexToRGB(i));
            }

            RB.CameraReset();

            mFormatStr.Set("@C// Draw individual pixels\n");
            mFormatStr.Append("@Kfor @N(@Kint @Ni = @L0@N; i < @L32@N; i++) {\n");
            mFormatStr.Append("    @[email protected](@Knew @MVector2i@N(@[email protected](@L").Append(RB.Ticks / 100.0f, 2).Append("f@N + i / @L10.0f@N) * @L128@N + @L128@N,\n");
            mFormatStr.Append("         @[email protected](@L").Append(RB.Ticks / 10.0f, 2).Append("f@N + i / @L2.0f@N) * @L6@N + @L6@N), MyRGBColor(i));\n}");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
        private void DrawSetTile(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            int      flags     = Random.Range(0, 2) == 0 ? 0 : RB.FLIP_V;
            Rect2i   clipRect  = new Rect2i(x + 16, y + 82, 250, 268);
            Vector2i cameraPos = new Vector2i((int)(Mathf.Sin(RB.Ticks / 50.0f) * 128) + 128, (int)(Mathf.Sin(RB.Ticks / 10.0f) * 16) + 16);
            string   flagsStr  = string.Empty;

            if (flags != 0)
            {
                flagsStr = ", @[email protected]_V";
            }

            RB.MapSpriteSet(0, new Vector2i(Random.Range(0, 38), Random.Range(0, 26)), Random.Range(RB.SpriteIndex(0, 4), RB.SpriteIndex(4, 4)), Color.white, flags);

            RB.ClipSet(clipRect);

            RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22));

            RB.CameraSet(cameraPos);
            RB.DrawMapLayer(0);
            RB.CameraReset();
            RB.DrawRect(clipRect, DemoUtil.IndexToRGB(21));

            RB.ClipReset();

            mFormatStr.Set("@C// Set specific tile at specific map layer, sprite flags\n");
            mFormatStr.Append("@[email protected](@L0@N, @Knew @MVector2i@N(@L").Append(Random.Range(0, 60)).Append("@N, @L").Append(Random.Range(0, 12)).Append("@N), @L").Append(Random.Range(RB.SpriteIndex(0, 4), RB.SpriteIndex(4, 4))).Append(", 0").Append(flagsStr).Append("@N);\n");
            mFormatStr.Append("@[email protected](@Knew@N @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N));\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N),\n   @I22);\n");
            mFormatStr.Append("@[email protected](@Knew@N @MVector2i@N(@L").Append(cameraPos.x).Append("@N, @L").Append(cameraPos.y).Append("@N));\n");
            mFormatStr.Append("@[email protected](@L0@N);\n");
            mFormatStr.Append("@[email protected]();\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N),\n");
            mFormatStr.Append("   @I21);");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #24
0
        private void DrawPositional(int x, int y)
        {
            RB.CameraSet(new Vector2i(-x, -y));

            mFormatStr.Set("@C// RetroBlit supports positional sounds. Simply\n");
            mFormatStr.Append("@C// set the position of your sound, and the\n");
            mFormatStr.Append("@C// position of the listener!\n");
            mFormatStr.Append("@N\n");
            mFormatStr.Append("@Kvoid@N Init() {\n");
            mFormatStr.Append("   sndRef = @[email protected](waterfallSnd);\n");
            mFormatStr.Append("   @[email protected](sndRef, @Ltrue@N);\n");
            mFormatStr.Append("}\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@Kvoid@N Update() {\n");
            mFormatStr.Append("   @[email protected](sndRef, @Knew@N @MVector2i@N(@L" + mSoundPos.x + "@N, @L" + mSoundPos.y + "@N));\n");
            mFormatStr.Append("   @[email protected](@Knew@N @MVector2i@N(@L" + mListenerPos.x + "@N, @L" + mListenerPos.y + "@N));\n");
            mFormatStr.Append("}\n");

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

            mPositionalButton.Render();

            for (int i = 0; i < (int)(10 * RB.SoundVolumeGet(mPosSoundRef)); i++)
            {
                int radius = 3;
                RB.DrawEllipse(new Vector2i((i * 23) + 4, mListenerPos.y - 3), new Vector2i(radius, radius), DemoUtil.IndexToRGB(2));
            }

            // Use absolute coordinates for drawing ear/rain drop
            RB.CameraReset();

            var volAlpha = (byte)(RB.SoundVolumeGet(mPosSoundRef) * 255);

            RB.AlphaSet(volAlpha);
            RB.DrawLine(mListenerPos, mSoundPos, DemoUtil.IndexToRGB(17));
            RB.DrawCopy(new Rect2i(0, 224, 14, 24), mListenerPos - new Vector2i(14 / 2, 24 / 2));
            RB.DrawCopy(new Rect2i(14, 224, 14, 24), mSoundPos - new Vector2i(14 / 2, 24 / 2));
            RB.AlphaSet(255);
        }
Example #25
0
        private void DrawAlpha(int x, int y, int spriteIndex)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 35));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 16, 16), -1, mOutputFrame, mOutputBackground);

            byte alpha = (byte)((Mathf.Sin(RB.Ticks / 20.0f) * 127) + 127);

            RB.DrawSprite(2, new Vector2i(0, 0));
            RB.AlphaSet(alpha);
            RB.DrawSprite(spriteIndex, new Vector2i(0, 0));
            RB.AlphaSet(255);

            RB.CameraReset();

            mFormatStr.Set("@C// Alpha transparency\n").Append("@[email protected](@L2@N, @Knew @MVector2i@N(@L0@N, @L0@N));\n");
            mFormatStr.Append("@[email protected](@L").Append(alpha).Append("@N);\n");
            mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MVector2i(@L0@N, @L0@N));");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #26
0
        private void DrawClip(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            int    clipWidth  = (int)((Mathf.Sin(RB.Ticks / 50.0f) * 64) + 64 + 4);
            int    clipHeight = (int)((Mathf.Sin((RB.Ticks / 50.0f) + 1) * 64) + 64 + 4);
            Rect2i clipRect   = new Rect2i(x + 150 - clipWidth + 8, y + 212 - clipHeight + 8, clipWidth * 2, clipHeight * 2);

            RB.ClipSet(clipRect);

            RB.DrawRectFill(new Rect2i(0, 0, 500, 500), DemoUtil.IndexToRGB(22));

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    int sx = (int)((Mathf.Sin((RB.Ticks / 100.0f) + (j * (Mathf.PI * 2 / 8)) + (RB.Ticks * 0.001f * i)) * i * 8) + 150 + x);
                    int sy = (int)((Mathf.Cos((RB.Ticks / 100.0f) + (j * (Mathf.PI * 2 / 8)) + (RB.Ticks * 0.001f * i)) * i * 8) + 212 + y);
                    RB.DrawSprite(3, new Vector2i(sx, sy));
                }
            }

            RB.ClipReset();

            mFormatStr.Set("@C// Set a clipping region\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(clipRect.x).Append("@N, @L").Append(clipRect.y).Append("@N, @L").Append(clipRect.width).Append("@N, @L").Append(clipRect.height).Append("@N));\n");
            mFormatStr.Append("@[email protected]@N(@Knew @MRect2i@N(@L0@N, @L0@N, @L500@N, @L500@N),\n");
            mFormatStr.Append("  @I22);\n");
            mFormatStr.Append("@Kfor @N(@Kint@N i = @L0@N; i < @L20@N; i++) {\n");
            mFormatStr.Append("  @Kfor @N(@Kint@N j = @L0@N; j < @L8@N; j++) {\n");
            mFormatStr.Append("    @[email protected](@L3@N, @Knew @MVector2i@N(\n");
            mFormatStr.Append("      ((@Kint@N)(@[email protected](@L").Append(RB.Ticks / 100.0f, 2).Append("f@N + j * (@[email protected] * @L2@N / @L8@N) + (@L").Append(RB.Ticks * 0.001f, 3).Append("f@N * i)) * i * @L8@N)@N),\n");
            mFormatStr.Append("      ((@Kint@N)(@[email protected](@L").Append(RB.Ticks / 100.0f, 2).Append("f@N + j * (@[email protected] * @L2@N / @L8@N) + (@L").Append(RB.Ticks * 0.001f, 3).Append("f@N * i)) * i * @L8@N)@N)));\n");
            mFormatStr.Append("  }\n");
            mFormatStr.Append("}");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #27
0
        private void DrawScale(int x, int y, int spriteIndex)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 25));
            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 235, 32), -1, mOutputFrame, mOutputBackground);

            Vector2i scaleSize = new Vector2i();

            scaleSize.x = (int)((Mathf.Sin(RB.Ticks / 20.0f) * 96) + 100);
            scaleSize.y = (int)((Mathf.Sin(RB.Ticks / 2 / 20.0f) * 16) + 17);

            RB.DrawSprite(spriteIndex, new Rect2i(0, 0, 32, 32));
            RB.DrawSprite(spriteIndex, new Rect2i(40, 0, scaleSize.x, scaleSize.y));

            RB.CameraReset();

            mFormatStr.Set("@C// Scale sprites by specifying destination rectangle\n");
            mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MRect2i@N(@L0@N, @L0@N, @L32@N, @L32@N));\n");
            mFormatStr.Append("@[email protected](@L").Append(spriteIndex).Append("@N, @Knew @MRect2i@N(@L40@N, @L0@N, @L").Append(scaleSize.x).Append("@N, @L").Append(scaleSize.y).Append("@N));");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
        private void DrawCode(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            mFormatStr.Set("@C// Draw into a Sprite Sheet to create simple and efficient tilemap animations!@N\n");
            mFormatStr.Append("@[email protected](myTilemapSpriteSheet);\n");
            mFormatStr.Append("@[email protected](myAnimationSpriteSheet);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Copy water animation@N\n");
            mFormatStr.Append("@[email protected](@Knew@N @MRect2i@N(@L").Append(mWaveOffset).Append("@N, @L0@N, @[email protected]()), @Knew@N @MVector2i@N(@L48@N, @L192@N));\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Clear fish frame@N\n");
            mFormatStr.Append("@[email protected](@Knew@N @MColor32@N(@L0@N, @L0@N, @L0@N, @L0@N), @Knew@N @MRect2i@N(@L80@N, @L192@N, @[email protected]()));\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Copy fish animation@N\n");

            if (mFishFrame < 7)
            {
                mFormatStr.Append("@[email protected](@Knew@N @MRect2i@N(@L").Append(mFishFrame * RB.SpriteSheetGet().grid.cellSize.width).Append("@N, @L");
                mFormatStr.Append(RB.SpriteSheetGet().grid.cellSize.height).Append("@N, @[email protected]()), @Knew@N @MVector2i@N(@L80@N, @L192@N));\n");
            }
            else
            {
                mFormatStr.Append("@[email protected](@[email protected], @[email protected]);\n");
            }

            mFormatStr.Append("\n");
            mFormatStr.Append("@[email protected]();\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Draw terrain and water@N\n");
            mFormatStr.Append("@[email protected](@L0@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Draw fish@N\n");
            mFormatStr.Append("@[email protected](@L1@N);\n");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #29
0
        private void DrawCustomFont(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 42));

            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 100, 11), -1, mOutputFrame, mOutputBackground);

            int c1 = ((int)RB.Ticks / 10) % 32;
            int c2 = (((int)RB.Ticks / 10) + 10) % 32;
            int c3 = (((int)RB.Ticks / 10) + 20) % 32;

            var color1 = DemoUtil.IndexToRGB(c1);
            var color2 = DemoUtil.IndexToRGB(c2);
            var color3 = DemoUtil.IndexToRGB(c3);

            mFormatStr.Set("HELLO @");
            mFormatStr.Append(color1.r, 2, FastString.FORMAT_HEX_CAPS).Append(color1.g, 2, FastString.FORMAT_HEX_CAPS).Append(color1.b, 2, FastString.FORMAT_HEX_CAPS).Append("FR@");
            mFormatStr.Append(color2.r, 2, FastString.FORMAT_HEX_CAPS).Append(color2.g, 2, FastString.FORMAT_HEX_CAPS).Append(color2.b, 2, FastString.FORMAT_HEX_CAPS).Append("IE@");
            mFormatStr.Append(color3.r, 2, FastString.FORMAT_HEX_CAPS).Append(color3.g, 2, FastString.FORMAT_HEX_CAPS).Append(color3.b, 2, FastString.FORMAT_HEX_CAPS).Append("ND");

            RB.Print(0, new Vector2i(0, 0), Color.white, mFormatStr);

            RB.CameraReset();

            mFormatStr.Set("@C// Print text with custom font from sprite sheet\n");
            mFormatStr.Append("@[email protected](@L0@N, @S'A'@N, @S'Z'@N, @Knew @MVector2i@N(@L0@N, @L16@N), @L0@N,\n");
            mFormatStr.Append("    @Knew @MVector2i@N(@L12@N, @L12@N), @L10@N, @L1@N, @L2@N, @Kfalse@N, @Ktrue@N);\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L0@N, @L0@N), @I01,\n");
            mFormatStr.Append("   @S\"HELLO @s@@");
            mFormatStr.Append(color1.r, 2, FastString.FORMAT_HEX_CAPS).Append(color1.g, 2, FastString.FORMAT_HEX_CAPS).Append(color1.b, 2, FastString.FORMAT_HEX_CAPS).Append("@SFR@s@@");
            mFormatStr.Append(color2.r, 2, FastString.FORMAT_HEX_CAPS).Append(color2.g, 2, FastString.FORMAT_HEX_CAPS).Append(color2.b, 2, FastString.FORMAT_HEX_CAPS).Append("@SIE@s@@");
            mFormatStr.Append(color3.r, 2, FastString.FORMAT_HEX_CAPS).Append(color3.g, 2, FastString.FORMAT_HEX_CAPS).Append(color3.b, 2, FastString.FORMAT_HEX_CAPS).Append("@SND\"@N);");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), DemoUtil.HighlightCode(mFormatStr, mFinalStr));
        }
Example #30
0
        private void DrawShapes(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            RB.CameraSet(new Vector2i(-x, -y - 66));

            DemoUtil.DrawOutputFrame(new Rect2i(0, 0, 263, 27), -1, mOutputFrame, mOutputBackground);

            for (int i = 0; i < mShapeSize.Length; i++)
            {
                mShapeSize[i].x = (int)((Mathf.Sin((RB.Ticks / 20.0f) + i) * 6) + 8);
                mShapeSize[i].y = (int)((Mathf.Sin((RB.Ticks / 2 / 20.0f) + i) * 6) + 8);
            }

            RB.DrawRect(new Rect2i(-mShapeSize[0].x + 13, -mShapeSize[0].y + 13, mShapeSize[0].x * 2, mShapeSize[0].y * 2), DemoUtil.IndexToRGB(6));
            RB.DrawRectFill(new Rect2i(40 - mShapeSize[1].x + 13, -mShapeSize[1].y + 13, mShapeSize[1].x * 2, mShapeSize[1].y * 2), DemoUtil.IndexToRGB(27));
            RB.DrawEllipse(new Vector2i(80 + 13, 13), new Vector2i(mShapeSize[2].x, mShapeSize[2].y), DemoUtil.IndexToRGB(8));
            RB.DrawEllipseFill(new Vector2i(120 + 13, 13), new Vector2i(mShapeSize[3].x, mShapeSize[3].y), DemoUtil.IndexToRGB(23));
            RB.DrawEllipseInvertedFill(new Vector2i(160 + 13, 13), new Vector2i(mShapeSize[4].x, mShapeSize[4].y), DemoUtil.IndexToRGB(2));
            Rect2i triRect = new Rect2i(-mShapeSize[5].x + 210, -mShapeSize[5].y + 13, mShapeSize[5].x * 2, mShapeSize[5].y * 2);

            RB.DrawTriangle(new Vector2i(triRect.x + (triRect.width / 2), triRect.y), new Vector2i(triRect.x, triRect.y + triRect.height), new Vector2i(triRect.x + triRect.width, triRect.y + triRect.height), DemoUtil.IndexToRGB(15));
            triRect = new Rect2i(-mShapeSize[6].x + 250, -mShapeSize[6].y + 13, mShapeSize[6].x * 2, mShapeSize[6].y * 2);
            RB.DrawTriangleFill(new Vector2i(triRect.x, triRect.y), new Vector2i(triRect.x + triRect.width, triRect.y), new Vector2i(triRect.x + (triRect.width / 2), triRect.y + triRect.height), DemoUtil.IndexToRGB(9));

            RB.CameraReset();

            mFormatStr.Set("@C// Draw primitive shapes\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L").Append(-mShapeSize[0].x + 13).Append("@N, @L").Append(-mShapeSize[0].y + 13).Append("@N, @L").Append(mShapeSize[0].x * 2).Append("@N, @L").Append(mShapeSize[0].y * 2).Append("@N), @I6);\n");
            mFormatStr.Append("@[email protected](@Knew @MRect2i(@L").Append(40 - mShapeSize[1].x + 13).Append("@N, @L").Append(-mShapeSize[1].y + 13).Append("@N, @L").Append(mShapeSize[1].x * 2).Append("@N, @L").Append(mShapeSize[1].y * 2).Append("@N), @I27);\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i(@L").Append(80 + 13).Append("@N, @L13@N), @Knew @MVector2i@N(@L").Append(mShapeSize[2].x).Append("@N, @L").Append(mShapeSize[2].y).Append("@N), @I8);\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L").Append(120 + 13).Append("@N, @L13@N), @Knew @MVector2i@N(@L").Append(mShapeSize[3].x).Append("@N, @L").Append(mShapeSize[3].y).Append("@N),\n   @I31);\n");
            mFormatStr.Append("@[email protected](@Knew @MVector2i@N(@L").Append(160 + 13).Append("@N, @L13@N),\n    @Knew @MVector2i@N(@L").Append(mShapeSize[4].x).Append("@N, @L").Append(mShapeSize[4].y).Append("@N), @I2);");

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