public override void OnUpdate()
        {
            if (animation < 1f)
            {
                animation = Math.Min(animation + Time.TimeMult * 0.016f, 1f);
            }

            if (ControlScheme.MenuActionHit(PlayerActions.Fire))
            {
                if (selectedIndex == 2)
                {
                    ControlScheme.IsSuspended = true;

                    api.PlaySound("MenuSelect", 0.5f);
                    api.BeginFadeOut(() => {
                        ControlScheme.IsSuspended = false;

                        LevelInitialization levelInit = new LevelInitialization(
                            episodeName,
                            levelName,
                            (GameDifficulty.Easy + selectedDifficulty),
                            (PlayerType.Jazz + selectedPlayerType)
                            );

                        if (!string.IsNullOrEmpty(previousEpisodeName))
                        {
                            ref PlayerCarryOver player = ref levelInit.PlayerCarryOvers[0];

                            byte lives      = Preferences.Get <byte>("EpisodeEnd_Lives_" + previousEpisodeName);
                            uint score      = Preferences.Get <uint>("EpisodeEnd_Score_" + previousEpisodeName);
                            short[] ammo    = Preferences.Get <short[]>("EpisodeEnd_Ammo_" + previousEpisodeName);
                            byte[] upgrades = Preferences.Get <byte[]>("EpisodeEnd_Upgrades_" + previousEpisodeName);

                            if (lives > 0)
                            {
                                player.Lives = lives;
                            }
                            if (score > 0)
                            {
                                player.Score = score;
                            }
                            if (ammo != null)
                            {
                                player.Ammo = ammo;
                            }
                            if (upgrades != null)
                            {
                                player.WeaponUpgrades = upgrades;
                            }
                        }

                        api.SwitchToLevel(levelInit);
                    });
Beispiel #2
0
        public override void OnUpdate()
        {
            if (animation < 1f)
            {
                animation = Math.Min(animation + Time.TimeMult * 0.016f, 1f);
            }

            if (ControlScheme.MenuActionHit(PlayerActions.Fire))
            {
                if (selectedIndex == 2)
                {
                    api.PlaySound("MenuSelect", 0.5f);
                    LevelInitialization carryOver = new LevelInitialization(
                        episodeName,
                        levelName,
                        (GameDifficulty.Easy + selectedDifficulty),
                        (PlayerType.Jazz + selectedPlayerType)
                        );

                    if (!string.IsNullOrEmpty(previousEpisodeName))
                    {
                        ref PlayerCarryOver player = ref carryOver.PlayerCarryOvers[0];

                        byte   lives    = Preferences.Get <byte>("EpisodeEnd_Lives_" + previousEpisodeName);
                        int[]  ammo     = Preferences.Get <int[]>("EpisodeEnd_Ammo_" + previousEpisodeName);
                        byte[] upgrades = Preferences.Get <byte[]>("EpisodeEnd_Upgrades_" + previousEpisodeName);

                        if (lives > 0)
                        {
                            player.Lives = lives;
                        }
                        if (ammo != null)
                        {
                            player.Ammo = ammo;
                        }
                        if (upgrades != null)
                        {
                            player.WeaponUpgrades = upgrades;
                        }
                    }

                    api.SwitchToLevel(carryOver);
                }
            }
Beispiel #3
0
        public void ChangeLevel(LevelInitialization levelInit = default(LevelInitialization))
        {
            ContentResolver.Current.ResetReferenceFlag();

            if (string.IsNullOrEmpty(levelInit.LevelName))
            {
                // Next level not specified, so show main menu
                ShowMainMenu(false);
            }
            else if (levelInit.LevelName == ":end")
            {
                // End of episode

                if (!string.IsNullOrEmpty(levelInit.LastEpisodeName) && levelInit.LastEpisodeName != "unknown")
                {
                    // ToDo: Implement time
                    Preferences.Set("EpisodeEnd_Time_" + levelInit.LastEpisodeName, (int)1);

                    if (levelInit.PlayerCarryOvers.Length == 1)
                    {
                        // Save CarryOvers only in SinglePlayer mode
                        ref PlayerCarryOver player = ref levelInit.PlayerCarryOvers[0];

                        Preferences.Set("EpisodeEnd_Lives_" + levelInit.LastEpisodeName, (byte)player.Lives);
                        Preferences.Set("EpisodeEnd_Score_" + levelInit.LastEpisodeName, player.Score);
                        if (player.Ammo != null)
                        {
                            Preferences.Set("EpisodeEnd_Ammo_" + levelInit.LastEpisodeName, player.Ammo);
                        }

                        // Save WeaponUpgrades only if at least one of them is upgraded
                        if (player.WeaponUpgrades != null)
                        {
                            for (int i = 0; i < player.WeaponUpgrades.Length; i++)
                            {
                                if (player.WeaponUpgrades[i] != 0)
                                {
                                    Preferences.Set("EpisodeEnd_Upgrades_" + levelInit.LastEpisodeName, player.WeaponUpgrades);
                                    break;
                                }
                            }
                        }
                    }

                    // Remove existing continue data
                    Preferences.Remove("EpisodeContinue_Misc_" + levelInit.LastEpisodeName);
                    Preferences.Remove("EpisodeContinue_Score_" + levelInit.LastEpisodeName);
                    Preferences.Remove("EpisodeContinue_Level_" + levelInit.LastEpisodeName);
                    Preferences.Remove("EpisodeContinue_Ammo_" + levelInit.LastEpisodeName);
                    Preferences.Remove("EpisodeContinue_Upgrades_" + levelInit.LastEpisodeName);

                    Preferences.Commit();

                    Episode lastEpisode = GetEpisode(levelInit.LastEpisodeName);
                    if (lastEpisode != null && !string.IsNullOrEmpty(lastEpisode.NextEpisode))
                    {
                        // Redirect to next episode
                        Episode nextEpisode = GetEpisode(lastEpisode.NextEpisode);

                        levelInit.EpisodeName = lastEpisode.NextEpisode;
                        levelInit.LevelName   = nextEpisode.FirstLevel;

                        // Start new level
                        LevelHandler handler = new LevelHandler(this, levelInit);

                        Scene.Current.DisposeLater();
                        Scene.SwitchTo(handler);

                        GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                        GC.Collect();
                        GC.WaitForPendingFinalizers();

                        GCSettings.LatencyMode = GCLatencyMode.LowLatency;

                        UpdateRichPresence(levelInit, null);
                    }
                    else
                    {
                        // Next episode not found...
                        ShowMainMenu(false);
                    }
                }
                else
                {
                    // Shouldn't happen...
                    ShowMainMenu(false);
                }
            }
Beispiel #4
0
        public override void OnUpdate()
        {
            if (selectAnimation < 1f)
            {
                selectAnimation = Math.Min(selectAnimation + Time.TimeMult * 0.016f, 1f);
            }

            if (expanded && expandedAnimation < 1f)
            {
                expandedAnimation = Math.Min(expandedAnimation + Time.TimeMult * 0.016f, 1f);
            }

            if (ControlScheme.MenuActionHit(PlayerActions.Fire))
            {
                if (episodes.Count > 0 && episodes[selectedIndex].IsAvailable)
                {
                    api.PlaySound("MenuSelect", 0.5f);

                    if (episodes[selectedIndex].CanContinue)
                    {
                        if (expanded)
                        {
                            // Restart episode
                            // Clear continue data
                            string episodeName = episodes[selectedIndex].Episode.Token;
                            Preferences.Remove("EpisodeContinue_Misc_" + episodeName);
                            Preferences.Remove("EpisodeContinue_Level_" + episodeName);
                            Preferences.Remove("EpisodeContinue_Ammo_" + episodeName);
                            Preferences.Remove("EpisodeContinue_Upgrades_" + episodeName);

                            Preferences.Commit();

                            episodes.Data[selectedIndex].CanContinue = false;
                            expanded          = false;
                            expandedAnimation = 0f;

                            api.SwitchToSection(new StartGameOptionsSection(
                                                    episodes[selectedIndex].Episode.Token,
                                                    episodes[selectedIndex].Episode.FirstLevel,
                                                    episodes[selectedIndex].Episode.PreviousEpisode
                                                    ));
                        }
                        else
                        {
                            ControlScheme.IsSuspended = true;

                            api.BeginFadeOut(() => {
                                ControlScheme.IsSuspended = false;

                                string episodeName = episodes[selectedIndex].Episode.Token;
                                string levelName   = Preferences.Get <string>("EpisodeContinue_Level_" + episodeName);

                                // Lives, Difficulty and PlayerType is saved in Misc array [Jazz2.Core/Game/Controller.cs: ~146]
                                byte[] misc = Preferences.Get <byte[]>("EpisodeContinue_Misc_" + episodeName);

                                LevelInitialization carryOver = new LevelInitialization(
                                    episodeName,
                                    levelName,
                                    (GameDifficulty)misc[1],
                                    (PlayerType)misc[2]
                                    );

                                ref PlayerCarryOver player = ref carryOver.PlayerCarryOvers[0];

                                if (misc[0] > 0)
                                {
                                    player.Lives = misc[0];
                                }

                                short[] ammo = Preferences.Get <short[]>("EpisodeContinue_Ammo_" + episodeName);
                                if (ammo != null)
                                {
                                    player.Ammo = ammo;
                                }

                                byte[] upgrades = Preferences.Get <byte[]>("EpisodeContinue_Upgrades_" + episodeName);
                                if (upgrades != null)
                                {
                                    player.WeaponUpgrades = upgrades;
                                }

                                api.SwitchToLevel(carryOver);
                            });