예제 #1
0
    // Update is called once per frame
    private void Update()
    {
        if (hasRevived && reviveFade2)
        {
            reviveFade2.transform.localPosition = new Vector3(0, 0, 0);
            if (reviveFade2.color.a > 0.0f)
            {
                reviveFade2.color = new Color(1, 1, 1, reviveFade2.color.a - Time.deltaTime / 2);
            }
            else
            {
                Destroy(reviveFade2.gameObject);
            }
        }
        if (!started)
        {
            return;
        }
        if (!revived)
        {
            if (!once && UnitaleUtil.IsOverworld)
            {
                once = true;
                utHeart.transform.SetParent(GameObject.Find("Canvas GameOver").transform);
                utHeart.transform.position           = heartPos;
                utHeart.GetComponent <Image>().color = heartColor;
                canvasOW = GameObject.Find("Canvas OW");
                canvasOW.SetActive(false);
                canvasTwo = GameObject.Find("Canvas Two");
                canvasTwo.SetActive(false);
            }
            else if (!once)
            {
                once = true;
                gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(16, 16);
                gameObject.GetComponent <Image>().enabled           = true; // abort the blink animation if it was playing
            }

            if (internalTimer > breakHeartAfter)
            {
                AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound("heartbeatbreaker"), Camera.main.transform.position, 0.75f);
                brokenHeartPrefab = Instantiate(brokenHeartPrefab);
                brokenHeartPrefab.transform.SetParent(UnitaleUtil.IsOverworld ? GameObject.Find("Canvas GameOver").transform : gameObject.transform);
                brokenHeartPrefab.GetComponent <RectTransform>().position = heartPos;
                brokenHeartPrefab.GetComponent <Image>().color            = heartColor;
                brokenHeartPrefab.GetComponent <Image>().enabled          = true;
                if (UnitaleUtil.IsOverworld)
                {
                    utHeart.GetComponent <Image>().enabled = false;
                }
                else
                {
                    Color color = gameObject.GetComponent <Image>().color;
                    gameObject.GetComponent <Image>().color = new Color(color.r, color.g, color.b, 0);
                    if (EnemyEncounter.script.GetVar("revive").Boolean)
                    {
                        Revive();
                    }
                }
                breakHeartAfter = 999.0f;
            }

            if (internalTimer > explodeHeartAfter)
            {
                AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound("heartsplosion"), Camera.main.transform.position, 0.75f);
                brokenHeartPrefab.GetComponent <Image>().enabled = false;
                heartShardInstances = new RectTransform[6];
                heartShardRelocs    = new Vector2[6];
                heartShardCtrl      = new LuaSpriteController[6];
                for (int i = 0; i < heartShardInstances.Length; i++)
                {
                    heartShardInstances[i] = Instantiate(heartShardPrefab).GetComponent <RectTransform>();
                    heartShardCtrl[i]      = new LuaSpriteController(heartShardInstances[i].GetComponent <Image>());
                    heartShardInstances[i].transform.SetParent(UnitaleUtil.IsOverworld ? GameObject.Find("Canvas GameOver").transform : gameObject.transform);
                    heartShardInstances[i].GetComponent <RectTransform>().position = heartPos;
                    heartShardInstances[i].GetComponent <Image>().color            = heartColor;
                    heartShardRelocs[i] = Random.insideUnitCircle * 100.0f;
                    heartShardCtrl[i].Set(heartShardAnim[0]);
                    heartShardCtrl[i].SetAnimation(heartShardAnim, 1 / 5f);
                }
                explodeHeartAfter = 999.0f;
            }

            if (internalTimer > gameOverAfter)
            {
                AudioClip originMusic = gameOverMusic.clip;
                if (deathMusic != null)
                {
                    try { gameOverMusic.clip = AudioClipRegistry.GetMusic(deathMusic); }
                    catch { UnitaleUtil.DisplayLuaError("game over screen", "The specified death music doesn't exist. (\"" + deathMusic + "\")"); }
                    if (gameOverMusic.clip == null)
                    {
                        gameOverMusic.clip = originMusic;
                    }
                }
                gameOverMusic.Play();
                gameOverAfter = 999.0f;
            }

            if (internalTimer > fluffybunsAfter)
            {
                if (deathText != null)
                {
                    List <TextMessage> text  = deathText.Select(str => new TextMessage(str, false, false)).ToList();
                    TextMessage[]      text2 = new TextMessage[text.Count + 1];
                    for (int i = 0; i < text.Count; i++)
                    {
                        text2[i] = text[i];
                    }
                    text2[text.Count] = new TextMessage("", false, false);
                    if (Random.Range(0, 400) == 44)
                    {
                        gameOverTxt.SetTextQueue(new[] {
                            new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]4", false, false),
                            new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]" + PlayerCharacter.instance.Name + "!\n[w:15]Stay determined...", false, false),
                            new TextMessage("", false, false)
                        });
                    }
                    else
                    {
                        gameOverTxt.SetTextQueue(text2);
                    }
                }
                else
                {
                    // This "4" made us laugh so hard that I kept it :P
                    int fourChance = Random.Range(0, 80);

                    string[] possibleDeathTexts = { "You cannot give up\njust yet...", "It cannot end\nnow...", "Our fate rests upon\nyou...",
                                                    "Don't lose hope...",              "You're going to\nbe alright!" };
                    if (fourChance == 44)
                    {
                        possibleDeathTexts[4] = "4";
                    }

                    gameOverTxt.SetTextQueue(new[] {
                        new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]" + possibleDeathTexts[Math.RandomRange(0, possibleDeathTexts.Length)], false, false),
                        new TextMessage("[color:ffffff][voice:v_fluffybuns][waitall:2]" + PlayerCharacter.instance.Name + "!\n[w:15]Stay determined...", false, false),
                        new TextMessage("", false, false)
                    });
                }

                fluffybunsAfter = 999.0f;
            }

            if (!done)
            {
                gameOverImage.color = new Color(1, 1, 1, gameOverFadeTimer);
                if (gameOverAfter >= 999.0f && gameOverFadeTimer < 1.0f)
                {
                    gameOverFadeTimer += Time.deltaTime / 2;
                    if (gameOverFadeTimer >= 1.0f)
                    {
                        gameOverFadeTimer = 1.0f;
                        done = true;
                    }
                }
                internalTimer += Time.deltaTime; // This is actually dangerous because done can be true before everything's done if timers are modified
            }
            else if (!exiting && !gameOverTxt.AllLinesComplete())
            {
                // Note: [noskip] only affects the UI controller's ability to skip, so we have to redo that here.
                if (InputUtil.Pressed(GlobalControls.input.Confirm) && gameOverTxt.LineComplete())
                {
                    gameOverTxt.NextLineText();
                }
            }
        }
        else
        {
            if (reviveTextSet && !reviveText.AllLinesComplete())
            {
                // Note: [noskip] only affects the UI controller's ability to skip, so we have to redo that here.
                if (InputUtil.Pressed(GlobalControls.input.Confirm) && reviveText.LineComplete())
                {
                    reviveText.NextLineText();
                }
            }
            else if (reviveTextSet && !exiting)
            {
                exiting = true;
            }
            else if (internalTimerRevive >= 5.0f && !reviveTextSet && breakHeartReviveAfter)
            {
                if (deathText != null)
                {
                    List <TextMessage> text = new List <TextMessage>();
                    foreach (string str in deathText)
                    {
                        text.Add(new TextMessage(str, false, false));
                    }
                    TextMessage[] text2 = new TextMessage[text.Count + 1];
                    for (int i = 0; i < text.Count; i++)
                    {
                        text2[i] = text[i];
                    }
                    text2[text.Count] = new TextMessage("", false, false);
                    reviveText.SetTextQueue(text2);
                }
                reviveTextSet = true;
            }
            else if (internalTimerRevive > 2.5f && internalTimerRevive < 4.0f)
            {
                brokenHeartPrefab.transform.localPosition = new Vector2(Random.Range(-3, 2), Random.Range(-3, 2));
            }
            else if (!breakHeartReviveAfter && internalTimerRevive > 2.5f)
            {
                breakHeartReviveAfter = true;
                AudioSource.PlayClipAtPoint(AudioClipRegistry.GetSound("heartbeatbreaker"), Camera.main.transform.position, 0.75f);
                if (UnitaleUtil.IsOverworld)
                {
                    utHeart.GetComponent <Image>().enabled = true;
                }
                else
                {
                    Color color = gameObject.GetComponent <Image>().color;
                    gameObject.GetComponent <Image>().color = new Color(color.r, color.g, color.b, 1);
                }
                Destroy(brokenHeartPrefab);
            }

            if (!reviveTextSet)
            {
                internalTimerRevive += Time.deltaTime;
            }

            if (exiting && reviveFade.color.a < 1.0f && reviveFade.isActiveAndEnabled)
            {
                reviveFade.color = new Color(1, 1, 1, reviveFade.color.a + Time.deltaTime / 2);
            }
            else if (exiting)
            {
                // repurposing the timer as a reset delay
                gameOverFadeTimer -= Time.deltaTime;
                if (gameOverMusic.volume - Time.deltaTime > 0.0f)
                {
                    gameOverMusic.volume -= Time.deltaTime;
                }
                else
                {
                    gameOverMusic.volume = 0.0f;
                }
                if (gameOverFadeTimer < -1.0f)
                {
                    reviveFade2 = Instantiate(reviveFade.gameObject).GetComponent <Image>();
                    reviveFade2.transform.SetParent(playerParent);
                    reviveFade2.transform.SetAsLastSibling();
                    reviveFade2.transform.localPosition = new Vector3(0, 0, 0);
                    reviveFade.color = new Color(1, 1, 1, 0);
                    EndGameOverRevive();
                    if (musicBefore != null)
                    {
                        musicBefore.clip = music;
                        musicBefore.Play();
                    }
                    hasRevived = true;
                }
            }
        }

        for (int i = 0; i < heartShardInstances.Length; i++)
        {
            heartShardInstances[i].position += (Vector3)heartShardRelocs[i] * Time.deltaTime;
            heartShardRelocs[i].y           -= 100f * Time.deltaTime;
        }

        if (gameOverTxt.textQueue == null)
        {
            return;
        }
        if (!exiting && gameOverTxt.AllLinesComplete() && gameOverTxt.LineCount() != 0)
        {
            exiting           = true;
            gameOverFadeTimer = 1.0f;
        }
        else if (exiting && gameOverFadeTimer > 0.0f)
        {
            gameOverImage.color = new Color(1, 1, 1, gameOverFadeTimer);
            if (!(gameOverFadeTimer > 0.0f))
            {
                return;
            }
            gameOverFadeTimer -= Time.deltaTime / 2;
            if (gameOverFadeTimer <= 0.0f)
            {
                gameOverFadeTimer = 0.0f;
            }
        }
        else if (exiting)
        {
            // repurposing the timer as a reset delay
            gameOverFadeTimer -= Time.deltaTime;
            if (gameOverMusic.volume - Time.deltaTime > 0.0f)
            {
                gameOverMusic.volume -= Time.deltaTime;
            }
            else
            {
                gameOverMusic.volume = 0.0f;
            }
            if (gameOverFadeTimer < -1.0f)
            {
                //StaticInits.Reset();
                EndGameOver();
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        //Effect update
        if (CheckEffect() && !start && !finish && !fadeMusic)
        {
            UpdateEffect();
        }
        //Stop the intro
        if (Input.anyKeyDown && !Input.GetKeyDown(KeyCode.F4))
        {
            Camera.main.GetComponent <AudioSource>().Stop();
            Camera.main.GetComponent <AudioSource>().volume = 1;
            SceneManager.LoadScene("TitleScreen");
        }
        //Fade out
        if (finish && !fadeMusic && !CheckEffect())
        {
            if (timer < 1.75f && !pause)
            {
                pause = true;
            }

            if (timer < 1.75f && timer > 1 && !sameImage)
            {
                img.color = new Color(img.color.r, img.color.g, img.color.b, (-timer + 1.75f) * 4 / 3);
            }
            else if (timer > 1.75f && pause)
            {
                pause     = false;
                timer     = 0.0f;
                finish    = false;
                img.color = new Color(img.color.r, img.color.g, img.color.b, 0);
                //Check end of intro
                if (text.AllLinesComplete())
                {
                    fadeMusic = true;
                    text.DestroyChars();
                }
                else
                {
                    img.sprite = SpriteRegistry.Get("Intro/" + imagePaths[++currentIndex]);
                    img.SetNativeSize();
                    img.rectTransform.pivot    = new Vector2(0.5f, 0.5f);
                    img.rectTransform.position = new Vector2(320, 240);
                    timerEffect = 0.0f;
                    if (specialEffects[currentIndex] != string.Empty)
                    {
                        try { ApplyEffect((Effect)Enum.Parse(typeof(Effect), specialEffects[currentIndex])); }
                        catch { UnitaleUtil.DisplayLuaError("IntroManager", "The effect " + specialEffects[currentIndex] + " doesn't exist."); }
                    }
                    text.NextLineText();
                    start = true;
                }
            }
            //Fade in
        }
        else if (start && !fadeMusic)
        {
            if (timer < 0.5f && !sameImage)
            {
                img.color = new Color(img.color.r, img.color.g, img.color.b, 2 * timer);
            }
            else
            {
                start     = false;
                img.color = new Color(img.color.r, img.color.g, img.color.b, 1);
                timer     = 0.0f;
                if (currentIndex != textsToDisplay.Length - 1)
                {
                    if (goToNextDirect[currentIndex + 1] == "Y")
                    {
                        sameImage = true;
                    }
                    else if (goToNextDirect[currentIndex + 1] == "N")
                    {
                        sameImage = false;
                    }
                    else if (imagePaths[currentIndex] == imagePaths[currentIndex + 1])
                    {
                        sameImage = true;
                    }
                    else
                    {
                        sameImage = false;
                    }
                }
                else
                {
                    sameImage = false;
                }
            }
            //End of intro
        }
        else if (fadeMusic)
        {
            if (timer < 1)
            {
                Camera.main.GetComponent <AudioSource>().volume = 1 - timer;
            }
            else
            {
                Camera.main.GetComponent <AudioSource>().Stop();
                Camera.main.GetComponent <AudioSource>().volume = 1;
                SceneManager.LoadScene("TitleScreen");
            }
            //End of current page
        }
        else if (text.LineComplete() && !start && !CheckEffect())
        {
            finish = true;
            timer  = 0;
        }
    }