Exemplo n.º 1
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.CompareTag("Player"))
        {
            PlayerData            data  = PlayerData.player;
            PlayerData.MelodyData mData = data.melodyData;

            if (npcTalk && !coroutineStopper)
            {
                if (npcState.currentState == state)
                {
                    StopAllCoroutines();
                    if (transform.GetChild(0) != null)
                    {
                        transform.GetChild(0).GetComponent <PopUpDescription>().Description();
                    }
                    StartCoroutine("FadeOut");
                    coroutineStopper = true;
                    hasCleared       = true;
                }
                else if (npcState.currentState.ToString() == "NPCIdle (State)")
                {
                    StopAllCoroutines();
                    if (transform.GetChild(0) != null)
                    {
                        transform.GetChild(0).GetComponent <PopUpDescription>().Description();
                    }
                    StartCoroutine("FadeIn");
                    coroutineStopper = true;
                    hasCleared       = true;
                }
            }

            else if (melodyPlayed && mData.currentMelody == melody && !coroutineStopper)
            {
                StopAllCoroutines();
                if (transform.GetChild(0) != null)
                {
                    transform.GetChild(0).GetComponent <PopUpDescription>().Description();
                }
                StartCoroutine("FadeOut");
                coroutineStopper = true;
                hasCleared       = true;
            }

            else if (actionPerformed && Input.GetButtonDown(buttonName) && !coroutineStopper)
            {
                StopAllCoroutines();
                if (transform.GetChild(0) != null)
                {
                    transform.GetChild(0).GetComponent <PopUpDescription>().Description();
                }
                StartCoroutine("FadeOut");
                coroutineStopper = true;
                hasCleared       = true;
            }
        }
    }
Exemplo n.º 2
0
    public override void Act(StateController controller)
    {
        PlayerData data = (PlayerData)controller.data;

        PlayerData.MelodyData mData = data.melodyData;

        bool facingRight = true;

        if (mData.currentMelody != null && Input.GetButtonDown("MelodyProjectileCast") && mData.projectileCooldownTimer.IsDone())
        {
            Vector3 offset = SpawnOffset;

            facingRight = data.transform.localScale.x > 0;

            if (!facingRight)
            {
                offset = Vector3.Scale(SpawnOffset, new Vector3(-1, 0, 0));
            }

            GameObject newProjectile = null;
            switch (mData.currentMelody)
            {
            case Melody.MelodyID.JumpMelody:
                newProjectile = Instantiate(mData.JumpMelodyProjectile);
                break;

            case Melody.MelodyID.SleepMelody:
                newProjectile = Instantiate(mData.SleepMelodyProjectile);
                break;

            case Melody.MelodyID.MagicResistMelody:
                newProjectile = Instantiate(mData.MagicResistMelodyProjectile);
                break;
            }

            MelodyProjectile melodyProjectile = newProjectile.GetComponent <MelodyProjectile>();
            melodyProjectile.Init(controller.transform.position + offset, facingRight);

            mData.projectileCooldownTimer.Start();
        }
    }
    public override void Act(StateController controller)
    {
        PlayerData data = (PlayerData)controller.data;

        PlayerData.MelodyData mData = data.melodyData;

        if (Input.GetButtonDown("PlayMelody") || InputExtender.GetAxisDown("PlayMelody Trigger"))
        {
            mData.playMelodyState = !mData.playMelodyState;

            // so you don't go to play melody when canceling a melody
            if (mData.currentMelody != null)
            {
                mData.playMelodyState = false;
                mData.playingFlute    = false;

                data.MelodyStoppedPlaying(mData.currentMelody);
                if (mData.currentMelody == Melody.MelodyID.MagicResistMelody)
                {
                    StoppedPlaying();
                }
                mData.currentMelody = null;
                data.melodyData.MelodyRange.enabled = false;
                controller.anim.SetBool("Channeling", false);
            }

            else if (mData.playMelodyState)   // on start reading input
            {
                AudioManager.FadeBGM();
                mData.playingFlute = true;
                data.songSheet.SetActive(true);

                if (mData.currentMelody != null)
                {
                    data.MelodyStoppedPlaying(mData.currentMelody);
                    if (mData.currentMelody == Melody.MelodyID.MagicResistMelody)
                    {
                        StoppedPlaying();
                    }
                }
                mData.currentMelody = null;
                data.melodyData.MelodyRange.enabled = false;
                controller.anim.SetBool("Channeling", true);
            }
            else   // on cancel playing
            {
                AudioManager.FadeBGMBackToNormal();
                mData.playingFlute = false;
                data.songSheet.SetActive(false);
                controller.anim.SetBool("Channeling", false);
            }
        }

        if (mData.playMelodyState)
        {
            // checks if a note is played
            Note notePlayed = null;
            //foreach (Note note in mData.Notes2) {
            //    if (note.CheckButton()) {
            //        mData.PlayedNotes.AddLast(note);
            //        notePlayed = note;
            //    }
            //}
            foreach (Note note in mData.Notes1)
            {
                if (note.CheckButton())
                {
                    mData.PlayedNotes.AddLast(note);
                    notePlayed = note;
                }
            }
            if (notePlayed != null)
            {
                AudioManager.PlayNote(notePlayed.audio);

                ParticleSystem m_fx = data.noteFX;
                ParticleSystem.TextureSheetAnimationModule m_anim = m_fx.textureSheetAnimation;
                m_anim.rowIndex = notePlayed.FXRowNumber;
                Instantiate(m_fx, new Vector2(data.transform.position.x, data.col.bounds.max.y), Quaternion.Euler(data.noteFX.transform.rotation.eulerAngles));
                m_fx.GetComponent <FXdestroyer>().hasPlayed = true;
            }

            while (mData.PlayedNotes.Count > mData.MaxSavedNotes)
            {
                mData.PlayedNotes.RemoveFirst();
            }

            // Checks id a melody have been played
            foreach (Melody melody in mData.melodies)
            {
                if (melody.CheckMelody(mData.PlayedNotes))
                {
                    mData.currentMelody = melody.melodyID;

                    if (mData.currentMelody == Melody.MelodyID.MagicResistMelody)
                    {
                        if (PlayedMagicResist != null)
                        {
                            PlayedMagicResist();
                        }
                    }
                    mData.playMelodyState     = false;
                    mData.MelodyRange.enabled = true;

                    data.MelodyPlayed(melody.melodyID);

                    AudioManager.FadeBGMBackToNormal();
                    mData.PlayedNotes.Clear();
                    data.songSheet.SetActive(false);

                    break;
                }
            }
        }
    }