Ejemplo n.º 1
0
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            RB.Clear(new Color32(127, 213, 221, 255));

            var game = (SuperFlagRun)RB.Game;

            if (game.GameMap == null)
            {
                RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load game TMX map.\nPlease try re-importing the map Demos/SuperFlagRun/GameMap.tmx in Unity");
                return;
            }

            // Draw Player One view
            RB.CameraReset();

            Vector2i cameraOffset;

            if (!game.SinglePlayer)
            {
                RB.ClipSet(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height / 2));
                cameraOffset = GetCameraOffset(mPlayerOne);
            }
            else
            {
                cameraOffset    = GetCameraOffset(mPlayerOne);
                cameraOffset.y -= RB.DisplaySize.height / 2;
            }

            RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y));
            RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_SKY);

            DrawScrollingClouds((int)cameraOffset.x, (int)cameraOffset.y);

            RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y));

            RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_BACKGROUND);
            RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TERRAIN);

            if (mWinningPlayer == 0)
            {
                mFlagOneSlot.Render();
            }

            mFlagOne.Render();
            mFlagTwo.Render();

            mPlayerTwo.Render();
            mPlayerOne.Render();

            // Draw Castles
            RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(16, RB.SpriteSheetGet().grid.cellSize.height * 26));
            RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i((RB.SpriteSheetGet().grid.cellSize.width *LEVEL_WIDTH) - 64, RB.SpriteSheetGet().grid.cellSize.height * 26), 0);

            if (!game.SinglePlayer)
            {
                // Draw Player Two view
                RB.ClipSet(new Rect2i(0, RB.DisplaySize.height / 2, RB.DisplaySize.width, RB.DisplaySize.height / 2));

                cameraOffset = GetCameraOffset(mPlayerTwo);

                RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2)));
                RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_SKY);

                DrawScrollingClouds((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2));

                cameraOffset = GetCameraOffset(mPlayerTwo);
                RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2)));

                RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_BACKGROUND);
                RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TERRAIN);

                if (mWinningPlayer == 0)
                {
                    mFlagTwoSlot.Render();
                }

                mFlagOne.Render();
                mFlagTwo.Render();

                mPlayerOne.Render();
                mPlayerTwo.Render();

                // Draw Castles
                RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(16, RB.SpriteSheetGet().grid.cellSize.height * 26));
                RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i((RB.SpriteSheetGet().grid.cellSize.width *LEVEL_WIDTH) - 64, RB.SpriteSheetGet().grid.cellSize.height * 26), 0);

                RB.ClipReset();
                RB.CameraReset();

                // Draw divider
                for (int x = 0; x < RB.DisplaySize.width; x += 16)
                {
                    RB.DrawSprite(RB.SpriteIndex(0, 0), new Vector2i(x, (RB.DisplaySize.height / 2) - 4));
                }
            }

            RB.ClipReset();
            RB.CameraReset();

            if (mWinningPlayer != 0)
            {
                string playerOneStr = "LOSER";
                string playerTwoStr = "WINNER";
                if (mWinningPlayer == RB.PLAYER_ONE)
                {
                    playerOneStr = "WINNER";
                    playerTwoStr = "LOSER";
                }

                int      textOffsetX = (int)(Mathf.Cos(Time.time * 6.0f) * 8);
                int      textOffsetY = (int)(Mathf.Sin(Time.time * 6.0f) * 5);
                Vector2i textSize;
                string   text = playerOneStr;
                textSize = RB.PrintMeasure(game.assets.gameFont, text);
                RB.Print(game.assets.gameFont, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2) + textOffsetX, (RB.DisplaySize.height / 4) - (textSize.height / 2) + textOffsetY), Color.white, text);

                text     = playerTwoStr;
                textSize = RB.PrintMeasure(game.assets.gameFont, text);
                RB.Print(game.assets.gameFont, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2) + textOffsetX, (RB.DisplaySize.height / 4 * 3) - (textSize.height / 2) + textOffsetY), Color.white, text);
            }

            // Let base render last so it can overlay the scene
            base.Render();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Render
        /// </summary>
        public override void Render()
        {
            RB.Clear(new Color32(127, 213, 221, 255));

            RB.CameraReset();

            SuperFlagRun game = (SuperFlagRun)RB.Game;

            if (game.TitleMap == null)
            {
                RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load title TMX map.\nPlease try re-importing the map Demos/SuperFlagRun/TitleMap.tmx in Unity");
                return;
            }

            RB.CameraSet(new Vector2i(RB.SpriteSize().width, 0));

            RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_SKY);

            DrawScrollingClouds();

            RB.CameraSet(new Vector2i(RB.SpriteSize().width, RB.SpriteSize().height * 12));

            RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_DECO);
            RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_TERRAIN);

            RB.CameraSet(new Vector2i(RB.SpriteSize().width, -RB.SpriteSize().height * 7));

            // Draw Flags
            mFlagOne.Render();
            mFlagTwo.Render();

            // Draw Players
            int x = (RB.SpriteSize().width * 3) + 8;
            int y = RB.SpriteSize().height * 3;

            RB.DrawSprite(RB.SpriteIndex(0, 2), new Vector2i(x, y), 0);
            RB.DrawSprite(RB.SpriteIndex(0, 3), new Vector2i(x, y + RB.SpriteSize().height), 0);

            x = RB.DisplaySize.width - (RB.SpriteSize().width * 2) - 8;
            RB.DrawSprite(RB.SpriteIndex(5, 2), new Vector2i(x, y), RB.FLIP_H);
            RB.DrawSprite(RB.SpriteIndex(5, 3), new Vector2i(x, y + RB.SpriteSize().height), RB.FLIP_H);

            // Draw Castles
            RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(RB.SpriteSize().width * 2, RB.SpriteSize().height * 4));
            RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i(RB.DisplaySize.width - (RB.SpriteSize().width * 3), RB.SpriteSize().height * 4), 0);

            // Draw Title
            RB.CameraReset();
            RB.SpriteSheetSet(SuperFlagRun.SPRITESHEET_TITLE);
            byte tint = (byte)((Mathf.Sin(Time.time * 2) * 60) + 196);

            RB.TintColorSet(new Color32(tint, tint, tint, 255));
            RB.DrawCopy(new Rect2i(0, 0, 323, 103), new Vector2i((RB.DisplaySize.width / 2) - (323 / 2), (int)(Mathf.Sin(Time.time * 2) * 6) + 15));
            RB.TintColorSet(Color.white);
            RB.SpriteSheetSet(SuperFlagRun.SPRITESHEET_SPRITES);

            // Draw Press Any Button
            string   str      = "PRESS ANY BUTTON";
            Vector2i textSize = RB.PrintMeasure(SuperFlagRun.GAME_FONT, str);

            RB.Print(SuperFlagRun.GAME_FONT, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2), (int)(RB.DisplaySize.height * 0.55f)), Color.white, str);

            RB.Print(new Vector2i(2, RB.DisplaySize.height - 9), Color.black, "RetroBlit technical demo game");

            // Let base render last so it can overlay the scene
            base.Render();
        }