示例#1
0
文件: Hud.cs 项目: ozgun-kara/jazz2
        void ICmpRenderer.Draw(IDrawDevice device)
        {
            canvas.Begin(device);

            Vector2 size = device.TargetSize;

            Rect view = new Rect(size);

            AdjustVisibleZone(ref view);

            float right  = view.X + view.W;
            float bottom = view.Y + view.H;

            int charOffset       = 0;
            int charOffsetShadow = 0;

            if (owner != null)
            {
                // Health & Lives
                {
                    string currentPlayer;
                    if (owner.PlayerType == PlayerType.Spaz)
                    {
                        currentPlayer = "CharacterSpaz";
                    }
                    else if (owner.PlayerType == PlayerType.Lori)
                    {
                        currentPlayer = "CharacterLori";
                    }
                    else if (owner.PlayerType == PlayerType.Frog)
                    {
                        currentPlayer = "CharacterFrog";
                    }
                    else
                    {
                        currentPlayer = "CharacterJazz";
                    }

                    DrawMaterial(currentPlayer, -1, view.X + 36, bottom + 1.6f, Alignment.BottomRight, new ColorRgba(0f, 0.4f));
                    DrawMaterial(currentPlayer, -1, view.X + 36, bottom, Alignment.BottomRight, ColorRgba.White);

                    string healthString = new string('|', owner.Health);

                    if (owner.Lives > 0)
                    {
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 - 0.5f, bottom - 16 + 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 + 0.5f, bottom - 16 - 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffset, healthString, view.X + 36 - 3, bottom - 16, Alignment.BottomLeft,
                                             null, 0.7f, charSpacing: 1.1f);

                        string livesString = "x" + owner.Lives.ToString(CultureInfo.InvariantCulture);
                        fontSmall.DrawString(ref charOffsetShadow, livesString, view.X + 36 - 4, bottom + 1f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.32f));
                        fontSmall.DrawString(ref charOffset, livesString, view.X + 36 - 4, bottom,
                                             Alignment.BottomLeft, ColorRgba.TransparentBlack);
                    }
                    else
                    {
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 - 0.5f, bottom - 3 + 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 + 0.5f, bottom - 3 - 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffset, healthString, view.X + 36 - 3, bottom - 3, Alignment.BottomLeft,
                                             null, 0.7f, charSpacing: 1.1f);
                    }
                }

                // Score
                {
                    DrawMaterial("PickupFood", -1, 3, 3 + 1.6f, Alignment.TopLeft, new ColorRgba(0f, 0.4f));
                    DrawMaterial("PickupFood", -1, 3, 3, Alignment.TopLeft, ColorRgba.White);

                    string scoreString = owner.Score.ToString("D8");
                    fontSmall.DrawString(ref charOffsetShadow, scoreString, 14, 5 + 1, Alignment.TopLeft,
                                         new ColorRgba(0f, 0.32f), 1f, charSpacing: 0.88f);
                    fontSmall.DrawString(ref charOffset, scoreString, 14, 5, Alignment.TopLeft,
                                         ColorRgba.TransparentBlack, 1f, charSpacing: 0.88f);
                }

                // Weapon
                if (owner.PlayerType != PlayerType.Frog)
                {
                    WeaponType weapon = owner.CurrentWeapon;
                    Vector2    pos    = new Vector2(right - 40, bottom);
                    string     currentWeaponString = GetCurrentWeapon(weapon, ref pos);

                    string ammoCount;
                    if (owner.WeaponAmmo[(int)weapon] < 0)
                    {
                        ammoCount = "x∞";
                    }
                    else
                    {
                        ammoCount = "x" + (owner.WeaponAmmo[(int)weapon] / 100).ToString(CultureInfo.InvariantCulture);
                    }
                    fontSmall.DrawString(ref charOffsetShadow, ammoCount, right - 40, bottom + 1f, Alignment.BottomLeft,
                                         new ColorRgba(0f, 0.32f), charSpacing: 0.96f);
                    fontSmall.DrawString(ref charOffset, ammoCount, right - 40, bottom, Alignment.BottomLeft,
                                         ColorRgba.TransparentBlack, charSpacing: 0.96f);

                    GraphicResource res;
                    if (graphics.TryGetValue(currentWeaponString, out res))
                    {
                        if (res.Base.FrameDimensions.Y < 20)
                        {
                            pos.Y -= MathF.Round((20 - res.Base.FrameDimensions.Y) * 0.5f);
                        }

                        DrawMaterial(currentWeaponString, -1, pos.X, pos.Y + 1.6f, Alignment.BottomRight, new ColorRgba(0f, 0.4f));
                        DrawMaterial(currentWeaponString, -1, pos.X, pos.Y, Alignment.BottomRight, ColorRgba.White);
                    }
                }
            }

            // Active Boss (health bar)
            if (activeBoss != null && activeBoss.MaxHealth != int.MaxValue)
            {
                const float TransitionTime = 60f;
                float       y, alpha;
                if (activeBossTime < TransitionTime)
                {
                    activeBossTime += Time.TimeMult;

                    if (activeBossTime > TransitionTime)
                    {
                        activeBossTime = TransitionTime;
                    }

                    y     = (TransitionTime - activeBossTime) / 8f;
                    y     = bottom * 0.1f - (y * y);
                    alpha = MathF.Max(activeBossTime / TransitionTime, 0f);
                }
                else
                {
                    y     = bottom * 0.1f;
                    alpha = 1f;
                }

                float perc = 0.08f + 0.84f * activeBoss.Health / activeBoss.MaxHealth;

                DrawMaterial("BossHealthBar", 0, size.X * 0.5f, y + 2f, Alignment.Center, new ColorRgba(0f, 0.1f * alpha));
                DrawMaterial("BossHealthBar", 0, size.X * 0.5f, y + 1f, Alignment.Center, new ColorRgba(0f, 0.2f * alpha));

                DrawMaterial("BossHealthBar", 0, size.X * 0.5f, y, Alignment.Center, new ColorRgba(1f, alpha));
                DrawMaterialClipped("BossHealthBar", 1, size.X * 0.5f, y, Alignment.Center, new ColorRgba(1f, alpha), perc, 1f);
            }

            // Misc.
            DrawLevelText(size, ref charOffset);
            DrawCoins(size, ref charOffset);
            DrawGems(size, ref charOffset);

            DrawPlatformSpecific(size);

            if (transitionManager != null)
            {
                transitionManager.Draw(device, canvas);
                if (transitionManager.IsCompleted && transitionManager.ActiveMode != TransitionManager.Mode.FadeOut)
                {
                    transitionManager = null;
                }
            }

            DrawDebugStrings();

            canvas.End();
        }
示例#2
0
文件: Hud.cs 项目: iidioter/jazz2
        void ICmpRenderer.Draw(IDrawDevice device)
        {
            canvas.Begin(device);

            Vector2 size = device.TargetSize;

            Rect view = new Rect(size);

            AdjustVisibleZone(ref view);

            float right  = view.X + view.W;
            float bottom = view.Y + view.H;

            int charOffset       = 0;
            int charOffsetShadow = 0;

            //if (!levelHandler.OverridePlayerDrawHud(this, device)) {
            // HUD is not overriden by level handler, so draw all common elements
            if (owner != null)
            {
                // Health & Lives
                {
                    string currentPlayer;
                    if (owner.PlayerType == PlayerType.Spaz)
                    {
                        currentPlayer = "CharacterSpaz";
                    }
                    else if (owner.PlayerType == PlayerType.Lori)
                    {
                        currentPlayer = "CharacterLori";
                    }
                    else if (owner.PlayerType == PlayerType.Frog)
                    {
                        currentPlayer = "CharacterFrog";
                    }
                    else
                    {
                        currentPlayer = "CharacterJazz";
                    }

                    DrawMaterial(currentPlayer, -1, view.X + 36, bottom + 1.6f, Alignment.BottomRight, new ColorRgba(0f, 0.4f));
                    DrawMaterial(currentPlayer, -1, view.X + 36, bottom, Alignment.BottomRight, ColorRgba.White);

                    string healthString = new string('|', owner.Health);

                    if (owner.Lives > 0)
                    {
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 - 0.5f, bottom - 16 + 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 + 0.5f, bottom - 16 - 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffset, healthString, view.X + 36 - 3, bottom - 16, Alignment.BottomLeft,
                                             null, 0.7f, charSpacing: 1.1f);

                        string livesString = "x" + owner.Lives.ToString(CultureInfo.InvariantCulture);
                        fontSmall.DrawString(ref charOffsetShadow, livesString, view.X + 36 - 4, bottom + 1f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.32f));
                        fontSmall.DrawString(ref charOffset, livesString, view.X + 36 - 4, bottom,
                                             Alignment.BottomLeft, ColorRgba.TransparentBlack);
                    }
                    else
                    {
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 - 0.5f, bottom - 3 + 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffsetShadow, healthString, view.X + 36 - 3 + 0.5f, bottom - 3 - 0.5f,
                                             Alignment.BottomLeft, new ColorRgba(0f, 0.42f), 0.7f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffset, healthString, view.X + 36 - 3, bottom - 3, Alignment.BottomLeft,
                                             null, 0.7f, charSpacing: 1.1f);
                    }
                }

                // Stats / Score
#if MULTIPLAYER
                if (levelHandler is MultiplayerLevelHandler mlh)
                {
                    switch (mlh.CurrentLevelType)
                    {
                    case MultiplayerLevelType.Battle: {
                        string statsString = "\f[c:4]\f[s:100]+" + mlh.StatsKills.ToString(CultureInfo.InvariantCulture) + " \f[c:2]\f[s:85]/\f[c:0]\f[s:100] -" + mlh.StatsDeaths.ToString(CultureInfo.InvariantCulture);
                        fontSmall.DrawString(ref charOffsetShadow, statsString, 14, 5 + 1, Alignment.TopLeft,
                                             new ColorRgba(0f, 0.32f), 1f, charSpacing: 0.88f);
                        fontSmall.DrawString(ref charOffset, statsString, 14, 5, Alignment.TopLeft,
                                             ColorRgba.TransparentBlack, 1f, charSpacing: 0.88f);

                        break;
                    }

                    case MultiplayerLevelType.Race: {
                        if (mlh.StatsLapsTotal > 0 && mlh.StatsLaps < mlh.StatsLapsTotal)
                        {
                            string statsString1 = (mlh.StatsLaps + 1).ToString(CultureInfo.InvariantCulture);
                            fontMedium.DrawString(ref charOffsetShadow, statsString1, 32, 10 + 1, Alignment.TopRight,
                                                  new ColorRgba(0f, 0.32f), 1f, charSpacing: 1f);
                            fontMedium.DrawString(ref charOffset, statsString1, 32, 10, Alignment.TopRight,
                                                  new ColorRgba(0.62f, 0.44f, 0.34f, 0.5f), 1f, charSpacing: 1f);

                            string statsString2 = "/" + mlh.StatsLapsTotal.ToString(CultureInfo.InvariantCulture);
                            fontSmall.DrawString(ref charOffsetShadow, statsString2, 36, 20 + 1, Alignment.TopLeft,
                                                 new ColorRgba(0f, 0.32f), 1f, charSpacing: 1.1f);
                            fontSmall.DrawString(ref charOffset, statsString2, 36, 20, Alignment.TopLeft,
                                                 new ColorRgba(0.56f, 0.50f, 0.42f, 0.5f), 1f, charSpacing: 1.1f);
                        }
                        break;
                    }

                    case MultiplayerLevelType.TreasureHunt: {
                        DrawMaterial("PickupGem", -1, 14, 20, Alignment.Left,
                                     new ColorRgba(0f, 0.4f), 0.6f, 0.6f);
                        DrawMaterial("PickupGem", -1, 14, 20, Alignment.Left,
                                     new ColorRgba(1f, 1f), 0.6f, 0.6f);

                        string statsString1 = "\f[c:1]\f[s:80]" + mlh.StatsLaps.ToString(CultureInfo.InvariantCulture);
                        fontMedium.DrawString(ref charOffsetShadow, statsString1, 38, 10 + 1, Alignment.TopLeft,
                                              new ColorRgba(0f, 0.32f), 1f, charSpacing: 0.8f);
                        fontMedium.DrawString(ref charOffset, statsString1, 38, 10, Alignment.TopLeft,
                                              new ColorRgba(0.7f, 0.45f, 0.42f, 0.5f), 1f, charSpacing: 0.8f);

                        string statsString2 = "\f[c:8]\f[s:110]/" + mlh.StatsLapsTotal.ToString(CultureInfo.InvariantCulture);
                        fontSmall.DrawString(ref charOffsetShadow, statsString2, 60, 18 + 1, Alignment.TopLeft,
                                             new ColorRgba(0f, 0.32f), 1f, charSpacing: 1.1f);
                        fontSmall.DrawString(ref charOffset, statsString2, 60, 18, Alignment.TopLeft,
                                             new ColorRgba(0.56f, 0.50f, 0.42f, 0.5f), 1f, charSpacing: 1.1f);

                        break;
                    }
                    }
                }
                else
                {
#endif
                DrawMaterial("PickupFood", -1, 3, 3 + 1.6f, Alignment.TopLeft, new ColorRgba(0f, 0.4f));
                DrawMaterial("PickupFood", -1, 3, 3, Alignment.TopLeft, ColorRgba.White);

                string scoreString = owner.Score.ToString("D8");
                fontSmall.DrawString(ref charOffsetShadow, scoreString, 14, 5 + 1, Alignment.TopLeft,
                                     new ColorRgba(0f, 0.32f), 1f, charSpacing: 0.88f);
                fontSmall.DrawString(ref charOffset, scoreString, 14, 5, Alignment.TopLeft,
                                     ColorRgba.TransparentBlack, 1f, charSpacing: 0.88f);
#if MULTIPLAYER
            }
#endif

                // Weapon
                if (owner.PlayerType != PlayerType.Frog)
                {
                    WeaponType weapon = owner.CurrentWeapon;
                    Vector2    pos    = new Vector2(right - 40, bottom);
                    string     currentWeaponString = GetCurrentWeapon(weapon, ref pos);

                    string ammoCount;
                    if (owner.WeaponAmmo[(int)weapon] < 0)
                    {
                        ammoCount = "x∞";
                    }
                    else
                    {
                        ammoCount = "x" + (owner.WeaponAmmo[(int)weapon] / 100).ToString(CultureInfo.InvariantCulture);
                    }
                    fontSmall.DrawString(ref charOffsetShadow, ammoCount, right - 40, bottom + 1f, Alignment.BottomLeft,
                                         new ColorRgba(0f, 0.32f), charSpacing: 0.96f);
                    fontSmall.DrawString(ref charOffset, ammoCount, right - 40, bottom, Alignment.BottomLeft,
                                         ColorRgba.TransparentBlack, charSpacing: 0.96f);

                    GraphicResource res;
                    if (graphics.TryGetValue(currentWeaponString, out res))
                    {
                        if (res.Base.FrameDimensions.Y < 20)
                        {
                            pos.Y -= MathF.Round((20 - res.Base.FrameDimensions.Y) * 0.5f);
                        }

                        DrawMaterial(currentWeaponString, -1, pos.X, pos.Y + 1.6f, Alignment.BottomRight, new ColorRgba(0f, 0.4f));
                        DrawMaterial(currentWeaponString, -1, pos.X, pos.Y, Alignment.BottomRight, ColorRgba.White);
                    }
                }
            }

            // Active Boss (health bar)
            if (activeBoss != null && activeBoss.MaxHealth != int.MaxValue)
            {
                const float TransitionTime = 60f;
                float       y, alpha;
                if (activeBossTime < TransitionTime)
                {
                    activeBossTime += Time.TimeMult;

                    if (activeBossTime > TransitionTime)
                    {
                        activeBossTime = TransitionTime;
                    }

                    y     = (TransitionTime - activeBossTime) / 8f;
                    y     = bottom * 0.1f - (y * y);
                    alpha = MathF.Max(activeBossTime / TransitionTime, 0f);
                }
                else
                {
                    y     = bottom * 0.1f;
                    alpha = 1f;
                }

                float perc = 0.08f + 0.84f * activeBoss.Health / activeBoss.MaxHealth;

                DrawMaterial("BossHealthBar", 0, size.X * 0.5f, y + 2f, Alignment.Center, new ColorRgba(0f, 0.1f * alpha));
                DrawMaterial("BossHealthBar", 0, size.X * 0.5f, y + 1f, Alignment.Center, new ColorRgba(0f, 0.2f * alpha));

                DrawMaterial("BossHealthBar", 0, size.X * 0.5f, y, Alignment.Center, new ColorRgba(1f, alpha));
                DrawMaterialClipped("BossHealthBar", 1, size.X * 0.5f, y, Alignment.Center, new ColorRgba(1f, alpha), perc, 1f);
            }

            // Misc
            DrawLevelText(size, ref charOffset);
            DrawCoins(size, ref charOffset);
            DrawGems(size, ref charOffset);
            //}

            DrawPlatformSpecific(size);

            if (transitionManager != null)
            {
                transitionManager.Draw(device);
                if (transitionManager.IsCompleted && transitionManager.CurrentMode != TransitionManager.Mode.FadeOut)
                {
                    transitionManager = null;
                }
            }

            DrawDebugStrings();

            canvas.End();
        }
示例#3
0
文件: Hud.cs 项目: ozgun-kara/jazz2
 public void BeginFadeOut(bool smooth)
 {
     transitionManager = new TransitionManager(TransitionManager.Mode.FadeOut, LevelRenderSetup.TargetSize, smooth);
 }
示例#4
0
文件: Hud.cs 项目: iidioter/jazz2
 public void BeginFadeOut(bool smooth)
 {
     transitionManager = new TransitionManager(TransitionManager.Mode.FadeOut, smooth);
 }