Esempio n. 1
0
    public void PlayerWinAnimation()
    {
        if (SelectedTile != null)
        {
            Preview.Show(false);
            SelectedTile.Select(false);
            SelectedTile = null;
        }
        grabPoint = new Vector2(1000, 1000);
        winType.Run(timeInfo, collectedStars, RespawnManager.Stars.Length, ActionSelected);

        cts = new CancellationTokenSource();

        int current_bi       = SceneHelpers.GetCurrentLevelBuildIndex();
        int current_bi_world = SceneHelpers.GetWorldFromBuildIndex(current_bi);
        int next_bi          = SceneHelpers.GetNextLevelBuildIndex();
        int next_bi_world    = SceneHelpers.GetWorldFromBuildIndex(next_bi);

        if (current_bi_world > 0 && current_bi_world < next_bi_world)
        {
            next_bi = SceneHelpers.WorldCompleteBuildIndex;
        }

        // TODO: this if/else can be removed once we've guaranteed that every world has 10 levels
        // and replaced with just the statement inside the IF
        if (next_bi < SceneHelpers.SceneCount)
        {
            GameManager.Instance.AsyncLoadScene(next_bi, StartCoroutine(WaitActionSelected()), cts, null, false);
        }
        else
        {
            GameManager.Instance.SaveData.LastPlayedWorld = 0;
        }
    }
Esempio n. 2
0
    private IEnumerator Run(List <Instruction> instructions)
    {
        var smallWait = new WaitForSeconds(Player.ActionTime / 2f);

        foreach (Instruction i in instructions)
        {
            Console.HighlightLine(i.CorrespondingUILineNumber);
            yield return(i.Execute(Player));

            if (i.DecrementForLoopOnLine != null)
            {
                Console.DecrementLoop(i.DecrementForLoopOnLine.Value);
            }
            yield return(smallWait);
        }

        if (Player.ReachedExit)
        {
            var winModal = FindObjectOfType <WinModal>();
            int index    = SceneHelpers.GetCurrentLevelBuildIndex();
            GameManager.Instance.AsyncLoadScene(
                index + 1,
                StartCoroutine(winModal.Reveal()),
                onSceneSwitch: () => {
                StartCoroutine(winModal.Hide());
                Console.transform.parent.gameObject.SetActive(false);
                Player.transform.parent.gameObject.SetActive(false);
            },
                shouldUnloadCurrentScene: false);
        }
        else
        {
            StopRun();
        }
    }
Esempio n. 3
0
    public void PlayerWin(GoalFlag gf)
    {
        goalFlag = gf;
        Won      = true;

        Grid?.PlayerWon();

        int bi = SceneHelpers.GetCurrentLevelBuildIndex();

        SceneHelpers.GetWorldAndLevelFromBuildIndex(bi, out int world, out int level);

        // don't save data for tutorial levels
        if (world > 0 && level > 0)
        {
            timeInfo      = new TimeInfo();
            timeInfo.Time = ElapsedTime;

            LevelData[,] allLevelData = GameManager.Instance.SaveData.LevelData;
            LevelData ld = allLevelData[world - 1, level - 1];
            if (collectedStars > ld.MaxStarsCollected)
            {
                ld.MaxStarsCollected = collectedStars;
            }
            if (collectedStars >= 3)
            {
                if (ld.ThreeStarCompletionTime < 0 || ElapsedTime < ld.ThreeStarCompletionTime)
                {
                    ld.ThreeStarCompletionTime = ElapsedTime;
                    timeInfo.Record            = true;

                    // check for 3 star achievement, otherwise player would need
                    //  to visit world complete screen to get credit for 3 starring all levels
                    bool allThreeStar = true;
                    for (int i = 0; i < 10; i++)
                    {
                        LevelData other = allLevelData[world - 1, i];
                        if (other.MaxStarsCollected < 3)
                        {
                            allThreeStar = false;
                        }
                    }
                    if (allThreeStar)
                    {
                        GameManager.Instance.StoreCommunicator.AddAchievement($"World{world}AllStars");
                    }
                }
            }
            if (ld.AnyStarCompletionTime < 0 || ElapsedTime < ld.AnyStarCompletionTime)
            {
                ld.AnyStarCompletionTime = ElapsedTime;
                timeInfo.Record          = true;
            }
        }

        GameManager.Instance.SaveLevelCompleteData(bi + 1);
    }
Esempio n. 4
0
 public void OnShowComplete()
 {
     var(world, level) = SceneHelpers.GetWorldAndLevelFromBuildIndex(SceneHelpers.GetCurrentLevelBuildIndex());
     if (anim.GetFloat("direction") > 0)
     {
         foreach (var c in ConditionalPopups)
         {
             c.gameObject.SetActive(c.ShouldShow(world, level));
         }
     }
 }
Esempio n. 5
0
    public void ActionSelected(WinTypeAction w)
    {
        AcceptingInputs = false;

        int currentScene = SceneHelpers.GetCurrentLevelBuildIndex();

        // if we're not going to the next scene, cancel the load of the next scene
        if (w != WinTypeAction.Next)
        {
            cts.Cancel();
        }
        MMVibrationManager.Haptic(HapticTypes.Selection);
        switch (w)
        {
        case WinTypeAction.Menu:
            GameManager.Instance.LoadScene(SceneHelpers.MenuBuildIndex, StartCoroutine(winType.WhenTilesOffScreen()));
            break;

        case WinTypeAction.Reset:
            GameManager.Instance.ShowAd();
            Reset(false);
            break;

        case WinTypeAction.LevelSelect:
            GoToLevelSelect(false);
            break;

        case WinTypeAction.Next:
            // TODO: All this logic can be removed once we've guaranteed that every world has 10 levels
            int current_bi       = SceneHelpers.GetCurrentLevelBuildIndex();
            int current_bi_world = SceneHelpers.GetWorldFromBuildIndex(current_bi);
            int next_bi          = SceneHelpers.GetNextLevelBuildIndex();
            int next_bi_world    = SceneHelpers.GetWorldFromBuildIndex(next_bi);
            if (next_bi < SceneHelpers.SceneCount || (current_bi_world > 0 && current_bi_world < next_bi_world))
            {
                GameManager.Instance.ShowAd();

                // hide objects in the current level so that as the wintype animation is playing, we see the next level
                HideLevel();

                // once the tiles are offscreen, we can finally unload the level
                StartCoroutine(winType.WhenTilesOffScreen(() => {
                    GameManager.Instance.UnloadScene(currentScene, null);
                }));
            }
            else
            {
                GoToLevelSelect(false);
            }
            break;
        }
    }