Esempio n. 1
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));
        }
        /// <summary>
        /// Render the effect
        /// </summary>
        public override void Render()
        {
            var game = (RetroDungeoneerGame)RB.Game;

            var source = mSourceEntity.e;
            var target = mTargetEntity.e;

            if (source == null || target == null)
            {
                return;
            }

            var sourcePos = new Vector2i(source.pos.x * game.assets.spriteSheet.grid.cellSize.width, source.pos.y * game.assets.spriteSheet.grid.cellSize.height);

            sourcePos += new Vector2i(game.assets.spriteSheet.grid.cellSize.width / 2, game.assets.spriteSheet.grid.cellSize.height / 2);

            var targetPos = new Vector2i(target.pos.x * game.assets.spriteSheet.grid.cellSize.width, target.pos.y * game.assets.spriteSheet.grid.cellSize.height);

            targetPos += new Vector2i(game.assets.spriteSheet.grid.cellSize.width / 2, game.assets.spriteSheet.grid.cellSize.height / 2);

            var delta = new Vector2(targetPos.x - sourcePos.x, targetPos.y - sourcePos.y);
            var dist  = delta.magnitude;
            var dir   = delta;

            dir.Normalize();

            var perp = new Vector2(dir.y, -dir.x);

            var segmentLen = 4.0f;

            Color32[] colors = new Color32[] { new Color32(0x3c, 0xac, 0xd7, 255), new Color32(0x3c, 0xac, 0xd7, 255), Color.white, Color.white };

            var alpha = mAlphaFade / (float)FADE_FRAMES;

            RB.AlphaSet((byte)(alpha * 255));
            RB.TintColorSet(Color.white);

            for (int i = 0; i < 4; i++)
            {
                var segmentStart = sourcePos.ToVector2();
                var distleft     = dist;

                while (distleft > 12)
                {
                    var len = segmentLen;

                    var segmentEnd = segmentStart + (dir * len) + (perp * Random.Range(-1.5f, 1.5f));
                    distleft -= len;

                    RB.DrawLine(segmentStart, segmentEnd, colors[i]);

                    segmentStart = segmentEnd;
                }

                RB.DrawLine(segmentStart, targetPos, colors[i]);
            }

            RB.AlphaSet(255);
        }
Esempio n. 3
0
        /// <summary>
        /// Run the stress test
        /// </summary>
        protected override void StressTest()
        {
            var game = (StressTest)RB.Game;

            Random.InitState(0);

            for (int i = 0; i < mStressLevel; i++)
            {
                var wiggle = GetWiggle();

                var randRect = new Rect2i(
                    (int)(Random.Range(-game.spriteSheet.grid.cellSize.width * 0.75f, RB.DisplaySize.width - (game.spriteSheet.grid.cellSize.width * 0.25f)) + wiggle.x),
                    (int)(Random.Range(-game.spriteSheet.grid.cellSize.height * 0.75f, RB.DisplaySize.height - (game.spriteSheet.grid.cellSize.height * 0.25f)) + wiggle.y),
                    Random.Range(8, 64),
                    Random.Range(8, 64));

                int type = Random.Range(0, 5);
                if (type == 0)
                {
                    RB.DrawLine(new Vector2i(randRect.x, randRect.y), new Vector2i(randRect.x + randRect.width, randRect.y + randRect.height), mRandomColor[i]);
                }
                else if (type == 1)
                {
                    RB.DrawRect(randRect, mRandomColor[i]);
                }
                else if (type == 2)
                {
                    RB.DrawRectFill(randRect, mRandomColor[i]);
                }
                else if (type == 3)
                {
                    RB.DrawTriangleFill(
                        new Vector2i(randRect.x, randRect.y),
                        new Vector2i(randRect.x + randRect.width, randRect.y),
                        new Vector2i(randRect.x + (randRect.width / 2), randRect.y + randRect.height),
                        mRandomColor[i]);
                }
                else if (type == 4)
                {
                    RB.DrawTriangle(
                        new Vector2i(randRect.x, randRect.y),
                        new Vector2i(randRect.x + randRect.width, randRect.y),
                        new Vector2i(randRect.x + (randRect.width / 2), randRect.y + randRect.height),
                        mRandomColor[i]);
                }
            }
        }
Esempio n. 4
0
    public override void RenderForeground()
    {
        for (int i = 0; i < battle.rolls.Length; i++)
        {
            if (battle.locks[i])
            {
                RB.DrawSprite("Lock", lockPositions[i] - new Vector2i(6, 6));
                //RB.Print(new Rect2i(lockPositions[i] - new Vector2i(16, 8), new Vector2i(32, 16)), Color.black, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, "Locked");
            }
        }

        for (int i = 0; i < battle.rollsLeft; i++)
        {
            RB.DrawEllipseFill(new Vector2i(size.x / 5 - 10 + i * 10, size.y / 2 + 44), new Vector2i(4, 4), Color.white);
            RB.DrawEllipse(new Vector2i(size.x / 5 - 10 + i * 10, size.y / 2 + 44), new Vector2i(4, 4), Color.black);
        }

        if (infoPane.GetOpenTabIndex() == 1)
        {
            ElementDisplay[] displays = viewedSpell.GetElementDisplays(battle.BuildContext());
            for (int i = 0; i < displays.Length; i++)
            {
                displays[i].Render(size.width / 2 + 5 + i * 18, size.height - 50);
            }
        }

        if (renderTargeting)
        {
            if (targetPawn != null)
            {
                RB.AlphaSet(96);
                RB.DrawRectFill(new Rect2i(0, 0, size), Color.black);
                RB.AlphaSet(255);
                pawnCards[targetPawn].Render();
                RB.DrawRect(targetRect, Color.yellow);
                RB.DrawPixel(targetPoint - new Vector2i(1, 0), Color.white);
                //RB.DrawRect(targetRect.Offset(new Vector2i(0, 0)).Expand(1), Color.black);
                originButton.Render();
            }
            RB.DrawPixel(originPoint + new Vector2i(1, 0), Color.white);
            //RB.DrawRect(new Rect2i(originButton.pos, originButton.size).Expand(2), Color.black);
            RB.DrawLine(originPoint + new Vector2i(0, 1), targetPoint + new Vector2i(0, 1), Color.yellow);
            RB.DrawLine(originPoint, targetPoint, Color.white);
            RB.DrawLine(originPoint - new Vector2i(0, 1), targetPoint - new Vector2i(0, 1), Color.yellow);
        }
    }
Esempio n. 5
0
        private void DrawSound(int x, int y)
        {
            int barHeight = 24;

            if (mAudioProgress >= 0.999f)
            {
                var rect = new Rect2i(x, y, mSpriteSheet.sheetSize.width, barHeight);
                RB.DrawRectFill(rect, DemoUtil.IndexToRGB(6));

                var prev   = new Vector2i(0, 0);
                var offset = new Vector2i(rect.x, rect.y + (rect.height / 2));
                var freq   = (Mathf.Sin(RB.Ticks / 20.0f) * 0.4f) + 0.25f;

                for (int i = 0; i <= rect.width; i += 4)
                {
                    float j     = (rect.width / 4) - (i / 2);
                    float freq2 = Mathf.Sin(j * freq);
                    float amp   = ((rect.height - 2) / 2) * Mathf.Cos(j / 10.0f) * Mathf.Sin(j / 20.0f);

                    if (i > rect.width / 2)
                    {
                        amp = -amp;
                    }

                    var point = new Vector2i(i, freq2 * amp);
                    RB.DrawLine(prev + offset, point + offset, DemoUtil.IndexToRGB(1));
                    prev = point;
                }

                rect = new Rect2i(x, y, mSpriteSheet.sheetSize.width, barHeight);
                RB.DrawRect(rect, DemoUtil.IndexToRGB(4));
            }
            else
            {
                var rect = new Rect2i(x, y, (int)(mSpriteSheet.sheetSize.width * mAudioProgress), barHeight);
                RB.DrawRectFill(rect, DemoUtil.IndexToRGB(4));

                rect = new Rect2i(x, y, mSpriteSheet.sheetSize.width, barHeight);
                RB.DrawRect(rect, DemoUtil.IndexToRGB(3));

                mFormatStr.Clear();
                mFormatStr.Append("Audio ").Append((int)(mAudioProgress * 100)).Append("%");
                RB.Print(new Vector2i(rect.x + 4, rect.y + 4), DemoUtil.IndexToRGB(5), mFormatStr);
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        private void DrawEase(Ease.Func func, string funcName, int x, int y, int width, int height)
        {
            byte spriteAlpha = 255;

            if (mT > 1.5f)
            {
                spriteAlpha = (byte)(((1.5f - mT) / 0.5f) * 255);
            }

            var graphColor      = DemoUtil.IndexToRGB(2);
            var lineColor       = DemoUtil.IndexToRGB(3);
            var scaleColor      = DemoUtil.IndexToRGB(24);
            var interStartColor = DemoUtil.IndexToRGB(27);
            var interEndColor   = DemoUtil.IndexToRGB(23);

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

            width  -= 28;
            height -= 16;

            // Draw graph
            int spaceBetweenLines = (height + 8) - 8;

            RB.DrawLine(new Vector2i(0, 8), new Vector2i(width, 8), graphColor);
            RB.DrawLine(new Vector2i(0, 8 + spaceBetweenLines), new Vector2i(width, 8 + spaceBetweenLines), graphColor);
            RB.Print(new Vector2i(0, 10), graphColor, funcName);

            // Draw line
            Vector2i p0 = new Vector2i(0, 8 + height);

            for (int i = 1; i <= width; i += 1)
            {
                int val = 0;
                val = Ease.Interpolate(func, 0, height, i / (float)width);

                Vector2i p1 = new Vector2i(i, 8 + height - val);

                RB.DrawLine(p0, p1, lineColor);

                p0 = p1;
            }

            // Draw movement sprite
            float t = mT;

            if (t > 1)
            {
                t = 1;
            }

            float ti = Ease.Interpolate(func, 0, 1.0f, t);

            Vector2i pos = new Vector2i(width + 8 - 4, 8 + height - Mathf.RoundToInt(ti * height) - 4);

            RB.DrawSprite(RB.SpriteIndex(7, 12), new Vector2i(width + 8 - 4, 8 - 4));
            RB.DrawSprite(RB.SpriteIndex(7, 12), new Vector2i(width + 8 - 4, 8 + height - 4));

            RB.AlphaSet(spriteAlpha);
            var highlightPos = new Vector2i((t * width) - 1, pos.y + 3);

            RB.DrawSprite(RB.SpriteIndex(7, 13), highlightPos);
            RB.DrawSprite(RB.SpriteIndex(7, 11), pos);
            RB.AlphaSet(255);

            int scale = 4 + Mathf.RoundToInt(ti * ((spaceBetweenLines / 2) - 4));

            RB.DrawRectFill(new Rect2i(width + 16, (height / 2) - scale + 8, 3, (scale * 2) + 1), scaleColor);

            var interColor = Ease.Interpolate(func, interStartColor, interEndColor, t);

            RB.DrawRectFill(new Rect2i(width + 20, 8, 3, 3), interEndColor);
            RB.DrawRectFill(new Rect2i(width + 20, 8 + spaceBetweenLines - 4 + 2, 3, 3), interStartColor);
            RB.DrawRectFill(new Rect2i(width + 20, 9 + 3, 3, spaceBetweenLines - 7), interColor);

            RB.CameraReset();
        }
Esempio n. 8
0
        private void DrawSpritePacking(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            mFormatStr.Set(
                "@DRetroBlit features a sprite packer that can cram your folders\n" +
                "full of sprites into optimal sprite sheets! To use it simply\n" +
                "create a sprite pack file (.sp) and point it to your sprite folder.");

            RB.Print(new Vector2i(4, 4), DemoUtil.IndexToRGB(25), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            y += 16;

            int indent       = 16;
            int row          = 0;
            int rowSpacing   = 9;
            int imageSpacing = 3;
            int fileColor    = 5;
            int folderColor  = 3;
            int alphaSprite  = 7;

            // Draw sprite pack file
            RB.CameraSet(new Vector2i(-170, -16));
            RB.DrawRectFill(new Rect2i(x - 4, y - 4, 108, 112), DemoUtil.IndexToRGB(2));

            mFormatStr.Set("@C// Source folder(s)\n");
            mFormatStr.Append("@C// relative to project\n");
            mFormatStr.Append("@C// root\n");
            mFormatStr.Append("@MSOURCE_FOLDER@N=@LSprites@N\n\n");
            mFormatStr.Append("@C// Output size\n");
            mFormatStr.Append("@MOUTPUT_WIDTH@N=@L96@N\n");
            mFormatStr.Append("@MOUTPUT_HEIGHT@N=@L96@N\n\n");
            mFormatStr.Append("@C// Trim empty space\n");
            mFormatStr.Append("@MTRIM@N=@Ltrue@N");

            RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(fileColor), "DemoSpritePack.sp");
            RB.DrawLine(new Vector2i(x, y + rowSpacing + 2), new Vector2i(x + 100, y + rowSpacing + 2), DemoUtil.IndexToRGB(3));
            RB.Print(new Vector2i(x, y + rowSpacing + rowSpacing), DemoUtil.IndexToRGB(fileColor), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            RB.DrawRectFill(new Rect2i(-32, 60, 6 * 3, 6), DemoUtil.IndexToRGB(5));
            RB.DrawRectFill(new Rect2i(-26, 54, 6, 6 * 3), DemoUtil.IndexToRGB(5));

            // Draw file listing
            RB.CameraSet(new Vector2i(-4, -16));
            RB.SpriteSheetSet(0);
            RB.DrawRectFill(new Rect2i(x - 4, y - 4, 120, 266), DemoUtil.IndexToRGB(2));

            mFormatStr.Set(
                "@DYour sprite source folders can be anywhere, but it's best to keep\n" +
                "them out of your @NAssets@D folder so that Unity does not put your\n" +
                "source sprites into the game @NAsset Resources@D!\n" +
                "\n" +
                "When you change your source sprites be sure to manually re-import\n" +
                "your sprite pack because Unity can't detect sprite changes outside\n" +
                "of the @NAssets@D folder!");

            RB.Print(new Vector2i(x - 4, y - 4 + 270), DemoUtil.IndexToRGB(25), DemoUtil.HighlightCode(mFormatStr, mFinalStr));

            RB.Print(new Vector2i(x, y + row), DemoUtil.IndexToRGB(folderColor), "Sprites/");
            row += rowSpacing;

            RB.Print(new Vector2i(x + indent, y + row), DemoUtil.IndexToRGB(folderColor), "Characters/");
            row += rowSpacing;

            RB.SpriteSheetSet(1);
            RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row));
            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteHero1, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteHero1.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "Hero1.png");
            row += rowSpacing;

            RB.SpriteSheetSet(1);
            RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row));
            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteHero2, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteHero2.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "Hero2.png");
            row += rowSpacing;

            RB.Print(new Vector2i(x + indent, y + row), DemoUtil.IndexToRGB(folderColor), "Terrain/");
            row += rowSpacing;

            RB.SpriteSheetSet(1);
            RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row));
            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteDirtCenter, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteDirtCenter.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "DirtCenter.png");
            row += rowSpacing;

            RB.SpriteSheetSet(1);
            RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row));
            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteDirtSide, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteDirtSide.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "DirtSide.png");
            row += rowSpacing;

            RB.SpriteSheetSet(1);
            RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row));
            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteGrassTop, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteGrassTop.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "GrassTop.png");
            row += rowSpacing;

            RB.SpriteSheetSet(1);
            RB.DrawSprite(alphaSprite, new Vector2i(x + (indent * 2), y + row));
            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteGrassTopRight, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteGrassTopRight.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "GrassTopRight.png");
            row += rowSpacing;

            RB.SpriteSheetSet(0);
            RB.DrawSprite(mSpriteWater, new Vector2i(x + (indent * 2), y + row));
            row += mSpriteWater.Size.height + imageSpacing;
            RB.Print(new Vector2i(x + (indent * 2), y + row), DemoUtil.IndexToRGB(fileColor), "Water.png");
            row += rowSpacing;

            RB.Print(new Vector2i(x + indent, y + row), DemoUtil.IndexToRGB(folderColor), "Other/");
            row += rowSpacing;
            RB.Print(new Vector2i(x + (indent * 3), y + row), DemoUtil.IndexToRGB(folderColor), "...\n...\n...");

            // Draw packed sprite sheet
            RB.CameraSet(new Vector2i(-168, -172));
            RB.DrawRectFill(new Rect2i(x, y, RB.SpriteSheetSize().width + 4, RB.SpriteSheetSize().height + 4), DemoUtil.IndexToRGB(2));

            RB.SpriteSheetSet(1);
            for (int gx = 0; gx < 6; gx++)
            {
                for (int gy = 0; gy < 6; gy++)
                {
                    RB.DrawSprite(alphaSprite, new Vector2i(x + 2 + (gx * 16), y + 2 + (gy * 16)));
                }
            }

            RB.SpriteSheetSet(0);
            RB.DrawCopy(new Rect2i(0, 0, RB.SpriteSheetSize().width, RB.SpriteSheetSize().height), new Vector2i(x + 2, y + 2));

            Vector2i p0 = new Vector2i((RB.SpriteSheetSize().width / 2) + 6, 8);
            Vector2i p1 = new Vector2i(p0.x - 10, p0.y - 10);
            Vector2i p2 = new Vector2i(p0.x + 10, p0.y - 10);

            RB.DrawTriangleFill(p0, p1, p2, DemoUtil.IndexToRGB(5));
            RB.DrawRectFill(new Rect2i(p0.x - 6, p1.y - 10, 11, 10), DemoUtil.IndexToRGB(5));

            RB.CameraReset();
        }
Esempio n. 9
0
        private void DrawMouse(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

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

            int color1       = 4;
            int color2       = 3;
            int colorOutline = 0;

            RB.DrawEllipseFill(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(color1));
            RB.DrawEllipseFill(new Vector2i(26, 54), new Vector2i(26, 20), DemoUtil.IndexToRGB(color1));
            RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawEllipse(new Vector2i(26, 54), new Vector2i(26, 20), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawRect(new Rect2i(0, 15, 53, 54 - 15), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(color1));

            RB.DrawLine(new Vector2i(52 / 3, 2), new Vector2i(52 / 3, 30), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawLine(new Vector2i(52 / 3 * 2, 2), new Vector2i(52 / 3 * 2, 30), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawLine(new Vector2i(0, 30), new Vector2i(52, 30), DemoUtil.IndexToRGB(colorOutline));

            if (RB.ButtonDown(RB.BTN_POINTER_A))
            {
                RB.ClipSet(new Rect2i(-RB.CameraGet().x + 1, -RB.CameraGet().y, (52 / 3) - 1, 30));
                RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5));
                RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
                RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5));
                RB.ClipReset();
            }

            if (RB.ButtonDown(RB.BTN_POINTER_B))
            {
                RB.ClipSet(new Rect2i(-RB.CameraGet().x + 35, -RB.CameraGet().y, 52 / 3, 30));
                RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5));
                RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
                RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5));
                RB.ClipReset();
            }

            if (RB.ButtonDown(RB.BTN_POINTER_C))
            {
                RB.ClipSet(new Rect2i(-RB.CameraGet().x + 18, -RB.CameraGet().y, (52 / 3) - 1, 30));
                RB.DrawEllipseFill(new Vector2i(26, 16), new Vector2i(26, 15), DemoUtil.IndexToRGB(5));
                RB.DrawEllipse(new Vector2i(26, 15), new Vector2i(26, 15), DemoUtil.IndexToRGB(colorOutline));
                RB.DrawRectFill(new Rect2i(1, 15, 53 - 2, 54 - 15), DemoUtil.IndexToRGB(5));
                RB.ClipReset();
            }

            if (RB.ButtonDown(RB.BTN_POINTER_A))
            {
                RB.Print(new Vector2i(9, 16), DemoUtil.IndexToRGB(colorOutline), "A");
            }
            else
            {
                RB.Print(new Vector2i(8, 15), DemoUtil.IndexToRGB(colorOutline), "A");
            }

            if (RB.ButtonDown(RB.BTN_POINTER_C))
            {
                RB.Print(new Vector2i(25, 16), DemoUtil.IndexToRGB(colorOutline), "C");
            }
            else
            {
                RB.Print(new Vector2i(24, 15), DemoUtil.IndexToRGB(colorOutline), "C");
            }

            if (RB.ButtonDown(RB.BTN_POINTER_B))
            {
                RB.Print(new Vector2i(41, 16), DemoUtil.IndexToRGB(colorOutline), "B");
            }
            else
            {
                RB.Print(new Vector2i(40, 15), DemoUtil.IndexToRGB(colorOutline), "B");
            }

            RB.DrawRectFill(new Rect2i(23, 36, 8, 24), DemoUtil.IndexToRGB(color2));
            int barSize = (int)(6 * mScrollDeltaAnim / 2.0f);

            barSize = Mathf.Clamp(barSize, -12, 12);

            if (barSize > 0)
            {
                RB.DrawRectFill(new Rect2i(23, 48 - barSize, 8, barSize), DemoUtil.IndexToRGB(5));
            }
            else if (barSize < 0)
            {
                RB.DrawRectFill(new Rect2i(23, 48, 8, -barSize), DemoUtil.IndexToRGB(5));
            }

            RB.DrawRect(new Rect2i(23, 36, 8, 24), DemoUtil.IndexToRGB(colorOutline));
            RB.DrawLine(new Vector2i(24, 48), new Vector2i(29, 48), DemoUtil.IndexToRGB(colorOutline));

            RB.CameraReset();
        }
Esempio n. 10
0
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            var demo = (DemoReel)RB.Game;

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

            mFormatStr.Set("@C// Test gamepad input for two players\n");
            mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_A, @[email protected]_ONE) {\n");
            mFormatStr.Append("   @C// Handle button A down for player one\n@N");
            mFormatStr.Append("}\n");
            mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_LEFT, @[email protected]_TWO) {\n");
            mFormatStr.Append("   @C// Handle button LEFT transitioning from \"up\" to \"down\"\n@N");
            mFormatStr.Append("}\n");
            mFormatStr.Append("@Kif @N(@[email protected](@MRetroBlit.@NBTN_MENU, @[email protected]_ANY) {\n");
            mFormatStr.Append("   @C// Handle button MENU transitioning from \"down\" to \"up\"\n@N");
            mFormatStr.Append("}");

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

            DrawGamepad(260, 15, RB.PLAYER_ONE);
            DrawGamepad(400, 15, RB.PLAYER_TWO);
            DrawMouse(540, 8);

            RB.DrawLine(new Vector2i(16, 85), new Vector2i(RB.DisplaySize.width - 16, 85), DemoUtil.IndexToRGB(2));

            mFormatStr.Set("@C// Test keyboard input\n");
            mFormatStr.Append("@Kif @N(@[email protected](@[email protected])) {\n");
            mFormatStr.Append("   @C// Handle Left Shift down\n@N");
            mFormatStr.Append("}\n\n");
            mFormatStr.Append("@C// Retrieve the string of characters typed since last update\n");
            mFormatStr.Append("@Kstring@n userInput += @[email protected]();");

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

            mFormatStr.Set("@C// Get pointer position (mouse or touch)\n");
            mFormatStr.Append("@[email protected](@L4@N, @[email protected]());\n\n");
            mFormatStr.Append("@C// Test pointer button input\n");
            mFormatStr.Append("@Kif @N(@[email protected](@[email protected]_POINTER_A)) {\n");
            mFormatStr.Append("   @C// Handle Pointer Button A down\n@N");
            mFormatStr.Append("}\n");

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

            DrawKeyboard(mKeyboardOffset.x, mKeyboardOffset.y);
            DrawInputString(14, 155);

            mNextButton.Render();
            mPrevButton.Render();

            if (RB.PointerPosValid())
            {
                RB.DrawSprite(4, RB.PointerPos());
            }

            if (!UnityEngine.Input.mousePresent)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (RB.PointerPosValid(i))
                    {
                        RB.DrawEllipse(RB.PointerPos(i), new Vector2i(64, 64), mTouchColor[i]);
                    }
                }
            }
        }
Esempio n. 11
0
        private void DrawAll(int x, int y)
        {
            var demo      = (DemoReel)RB.Game;
            var gridColor = DemoUtil.IndexToRGB(14);

            RB.Offscreen(0);
            RB.SpriteSheetSet(1);
            mWaveOffset = (int)((RB.Ticks / 2) % 8);
            RB.DrawCopy(new Rect2i(mWaveOffset, 0, RB.SpriteSize()), new Vector2i(24, 8));
            RB.Onscreen();

            Rect2i clipRectOverlap = mClipRect;

            clipRectOverlap.width += 400;

            if (mMap != null)
            {
                RB.DrawRectFill(mClipRect, DemoUtil.IndexToRGB(22));
            }

            RB.ClipSet(clipRectOverlap);
            DrawTilemap(mClipRect.x, mClipRect.y);
            RB.ClipReset();

            RB.CameraReset();

            // Blank out right side
            RB.AlphaSet(196);
            RB.DrawRectFill(new Rect2i(mClipRect.x + mClipRect.width, mClipRect.y, 300, mClipRect.height), DemoUtil.IndexToRGB(1));
            RB.AlphaSet(255);

            // Blank out left side
            RB.DrawRectFill(new Rect2i(0, mClipRect.y, mClipRect.x - 1, mClipRect.height), DemoUtil.IndexToRGB(1));

            RB.DrawRect(mClipRect, DemoUtil.IndexToRGB(7));

            if (mMap == null)
            {
                return;
            }

            RB.AlphaSet(128);

            mFinalStr.Set("Chunk Tile Offset:");
            RB.Print(new Vector2i(mClipRect.x, mClipRect.y - 16), gridColor, mFinalStr);

            RB.CameraSet(mChunkCameraPos - new Vector2i(mClipRect));

            int gxStart = 0;
            int gxEnd   = gxStart + (RB.DisplaySize.width * 2);

            for (int gx = gxStart; gx < gxEnd; gx += RB.MapChunkSize.width * RB.SpriteSize().x)
            {
                RB.DrawLine(new Vector2i(gx, -8), new Vector2i(gx, mClipRect.height + 4), gridColor);

                mFinalStr.Set(gx / RB.SpriteSize().x);
                RB.Print(new Vector2i(gx + 3, -8), gridColor, mFinalStr);
            }

            RB.AlphaSet(255);

            RB.CameraReset();

            RB.SpriteSheetSet(0);
        }
Esempio n. 12
0
        private void DrawTMX(int x, int y)
        {
            var demo = (DemoReel)RB.Game;

            Rect2i clipRect = new Rect2i(x, y, 340, 352);

            if (mMap != null)
            {
                RB.ClipSet(clipRect);
                RB.DrawRectFill(clipRect, DemoUtil.IndexToRGB(22));

                int scrollPos = -(int)RB.Ticks % (mMap.size.width * RB.SpriteSize().width);

                RB.CameraSet(new Vector2i(256, 144));
                RB.DrawMapLayer(1, new Vector2i(scrollPos, 0));
                RB.DrawMapLayer(1, new Vector2i(scrollPos + (mMap.size.width * RB.SpriteSize().width), 0));
                RB.DrawMapLayer(2);
                RB.DrawMapLayer(3);

                var objs = mMap.objectGroups["Objects"].objects;
                for (int i = 0; i < objs.Count; i++)
                {
                    var obj = objs[i];

                    switch (obj.shape)
                    {
                    case TMXObject.Shape.Rectangle:
                        RB.DrawRect(obj.rect, Color.red);
                        RB.Print(obj.rect, Color.red, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, obj.properties.GetString("name"));
                        break;

                    case TMXObject.Shape.Polyline:
                        for (int j = 0; j < obj.points.Count - 1; j++)
                        {
                            RB.DrawLine(
                                obj.points[j] + new Vector2i(obj.rect.x, obj.rect.y),
                                obj.points[j + 1] + new Vector2i(obj.rect.x, obj.rect.y),
                                Color.green);
                        }

                        break;

                    case TMXObject.Shape.Ellipse:
                        RB.DrawEllipse(obj.rect.center, new Vector2i(obj.rect.width / 2, obj.rect.height / 2), Color.yellow);
                        RB.Print(obj.rect, Color.yellow, RB.ALIGN_H_CENTER | RB.ALIGN_V_CENTER, obj.properties.GetString("name"));
                        break;
                    }
                }
            }
            else
            {
                RB.CameraReset();
                RB.ClipReset();
                RB.Print(new Vector2i(x + 4, y + 4), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/TilemapProps.tmx in Unity");
            }

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

            RB.ClipReset();

            x += 350;

            mFormatStr.Set("@C// Read shapes and their custom properties from TMX file\n");
            mFormatStr.Append("@NmyMap = @[email protected](@S\"Demos/DemoReel/TilemapProps\"@N);\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@Kvar@N objs = myMap.objectGroups[@S\"Objects\"@N].objects;\n");
            mFormatStr.Append("@Kfor@N (@Kint@N i = @L0@N; i < objs.Count; i++)\n");
            mFormatStr.Append("{\n");
            mFormatStr.Append("    @Kvar@N obj = obj;\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("    @Kswitch@N (obj.shape)\n");
            mFormatStr.Append("    {\n");
            mFormatStr.Append("        @Kcase@N @[email protected]:\n");
            mFormatStr.Append("            @[email protected](obj.rect, @[email protected]);\n");
            mFormatStr.Append("            @[email protected](obj.rect, @[email protected],\n");
            mFormatStr.Append("               @[email protected]_H_CENTER | @[email protected]_V_CENTER,\n");
            mFormatStr.Append("               obj.properties.GetString(\"name\"));\n");
            mFormatStr.Append("            @Kbreak@N;\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("        @Kcase@N @[email protected]:\n");
            mFormatStr.Append("            @Kfor@N (@Kint@N j = @L0@N; j < obj.points.Count - @L1@N; j++)\n");
            mFormatStr.Append("            {\n");
            mFormatStr.Append("                @[email protected](\n");
            mFormatStr.Append("                   obj.points[j] + @Knew@N @MVector2i@N(obj.rect.x, obj.rect.y),\n");
            mFormatStr.Append("                   obj.points[j + @L1@N] + @Knew@N @MVector2i@N(obj.rect.x, obj.rect.y),\n");
            mFormatStr.Append("                   @[email protected]);\n");
            mFormatStr.Append("            }\n");
            mFormatStr.Append("            @Kbreak@N;\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("        @Kcase@N @[email protected]:\n");
            mFormatStr.Append("            @[email protected](obj.rect.center,\n");
            mFormatStr.Append("               new @MVector2i@N(obj.rect.width / @L2@N, obj.rect.height / @L2@N),\n");
            mFormatStr.Append("               @[email protected]);\n");
            mFormatStr.Append("            @[email protected](obj.rect, @[email protected],\n");
            mFormatStr.Append("               @[email protected]_H_CENTER | RB.ALIGN_V_CENTER,\n");
            mFormatStr.Append("               obj.properties.GetString(@S\"name\"@N));\n");
            mFormatStr.Append("            @Kbreak@N;\n");
            mFormatStr.Append("    }\n");
            mFormatStr.Append("}\n");
            mFormatStr.Append("\n");
            mFormatStr.Append("@C// Also easily read tile custom properties\n");
            mFormatStr.Append("@Kvar@N props = @[email protected]<@MTMXProperties@N>(@L0@N, @Knew@N @MVector2i@N(@L2@N, @L5@N));\n");
            mFormatStr.Append("@Kint@N blocking = tileProps.GetInt(@S\"blocking\"@N);");

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

            Rect2i ss0Rect       = new Rect2i(0, 0, 16 * 7, 16 * 6);
            Rect2i ss1Rect       = new Rect2i(0, ss0Rect.y + ss0Rect.height + 16, 16 * 7, 16 * 2);
            Rect2i copyRectWater = new Rect2i(mWaveOffset + ss1Rect.x - 1, ss1Rect.y - 1, 16 + 2, 16 + 2);
            Rect2i destRectWater = new Rect2i(ss0Rect.x + (3 * 16), ss0Rect.y + (4 * 16), 16, 16);
            Rect2i copyRectFish  = new Rect2i((mFishFrame * 16) + ss1Rect.x - 1, ss1Rect.y - 1 + 16, 16 + 2, 16 + 2);
            Rect2i destRectFish  = new Rect2i(ss0Rect.x + (5 * 16), ss0Rect.y + (4 * 16), 16, 16);

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

            RB.Print(new Vector2i(ss0Rect.x, ss0Rect.y + ss0Rect.height + 2), Color.gray, "myTilemapSpriteSheet");
            RB.Print(new Vector2i(ss0Rect.x, ss1Rect.y + ss1Rect.height + 2), Color.gray, "myAnimationSpriteSheet");

            RB.SpriteSheetSet(spriteSheet1);

            // Draw alpha grid for sprite sheet 0
            for (int gx = 0; gx < ss0Rect.width; gx += 16)
            {
                for (int gy = 0; gy < ss0Rect.height; gy += 16)
                {
                    RB.DrawSprite(RB.SpriteIndex(7, 0), new Vector2i(gx + ss0Rect.x, gy + ss0Rect.y));
                }
            }

            // Draw alpha grid for sprite sheet 1
            for (int gx = 0; gx < ss1Rect.width; gx += 16)
            {
                for (int gy = 0; gy < ss1Rect.height; gy += 16)
                {
                    RB.DrawSprite(RB.SpriteIndex(7, 0), new Vector2i(gx + ss1Rect.x, gy + ss1Rect.y));
                }
            }

            RB.SpriteSheetSet(spriteSheet2);
            RB.DrawCopy(new Rect2i(0, 0, RB.SpriteSheetGet().sheetSize), new Vector2i(ss1Rect.x, ss1Rect.y));
            RB.SpriteSheetSet(spriteSheet1);

            int color = 7;

            RB.DrawCopy(new Rect2i(0, 16 * 8, ss0Rect.width, ss0Rect.height), new Vector2i(ss0Rect.x, ss0Rect.y));

            // Water copy rects
            RB.DrawRect(copyRectWater, DemoUtil.IndexToRGB(color));
            destRectWater.Expand(1);
            RB.DrawRect(destRectWater, DemoUtil.IndexToRGB(color));
            RB.DrawLine(
                new Vector2i(copyRectWater.x + (copyRectWater.width / 2), copyRectWater.y),
                new Vector2i(destRectWater.x + 8, destRectWater.y + 18),
                DemoUtil.IndexToRGB(color));

            // Fish copy rects
            if (mFishFrame < 7)
            {
                RB.DrawRect(copyRectFish, DemoUtil.IndexToRGB(color));
                destRectFish.Expand(1);
                RB.DrawRect(destRectFish, DemoUtil.IndexToRGB(color));
                RB.DrawLine(
                    new Vector2i(copyRectFish.x + (copyRectFish.width / 2), copyRectFish.y),
                    new Vector2i(destRectFish.x + 8, destRectFish.y + 18),
                    DemoUtil.IndexToRGB(color));
            }

            RB.CameraReset();
        }