コード例 #1
0
    // Start is called before the first frame update
    IEnumerator Start()
    {
        notePlayer            = FindObjectOfType <NotePlayer>();
        playerHealth          = FindObjectOfType <PlayerController>().GetComponent <Health>();
        gameMessageLine1.text = "";

        //round = defaultRound;
        //yield return new WaitForSeconds(1);

        SetupRoundData();

        print("Game Started");

        while (!gameIsOver)
        {
            print("=== START OF THE ROUND ===");
            playerHasAnswered = false;
            roundNumber++;
            roundsRemainingUI.text = "(" + roundNumber + "/" + totalNumberOfRounds + ")";

            // Wait Entry time
            yield return(new WaitForSeconds(roundEnterTime));

            // Play Note
            PianoKey.Note note = PlayRandomNote();
            print("Random note: " + note);

            // Wait for input...
            yield return(new WaitUntil(() => playerHasAnswered == true));

            // Check to see if input matches the note
            bool correctGuess = false;
            correctGuess = (note == playerGuess) ? true : false;

            // If the guess is incorrect, player takes damage
            if (correctGuess)
            {
                FindObjectOfType <PlayerController>().Boost();
            }
            else
            {
                TakeDamage(wrongGuessDamage);
            }

            // Check if the player is dead
            if (playerHealth.IsDead())
            {
                gameIsOver            = true;
                gameMessageLine1.text = "LOSE!";
            }

            // Check if we have played all the rounds
            if (roundNumber >= totalNumberOfRounds)
            {
                gameIsOver            = true;
                gameMessageLine1.text = "WIN!";
            }



            print("=== END OF THE ROUND ===");
            yield return(new WaitForSeconds(roundLeaveTime));
        }
    }
コード例 #2
0
 private PianoKey.Note PlayRandomNote()
 {
     PianoKey.Note note = possibleNotes[Random.Range(0, possibleNotes.Length)];
     notePlayer.PlayNote(note);
     return(note);
 }
コード例 #3
0
 public void PlayerGuesses(PianoKey.Note note)
 {
     playerGuess       = note;
     playerHasAnswered = true;
 }
コード例 #4
0
ファイル: NotePlayer.cs プロジェクト: Pythondark/StarTune
        public void PlayNote(PianoKey.Note note)
        {
            AudioClip noteSound;

            switch (note)
            {
            case PianoKey.Note.CMiddle:
                noteSound = MiddleC;
                break;

            case PianoKey.Note.CSharp:
                noteSound = CSharp;
                break;

            case PianoKey.Note.D:
                noteSound = D;
                break;

            case PianoKey.Note.DSharp:
                noteSound = DSharp;
                break;

            case PianoKey.Note.E:
                noteSound = E;
                break;

            case PianoKey.Note.F:
                noteSound = F;
                break;

            case PianoKey.Note.FSharp:
                noteSound = FSharp;
                break;

            case PianoKey.Note.G:
                noteSound = G;
                break;

            case PianoKey.Note.GSharp:
                noteSound = GSharp;
                break;

            case PianoKey.Note.A:
                noteSound = A;
                break;

            case PianoKey.Note.ASharp:
                noteSound = ASharp;
                break;

            case PianoKey.Note.B:
                noteSound = B;
                break;

            case PianoKey.Note.CHigh:
                noteSound = HighC;
                break;

            default:
                noteSound = MiddleC;
                break;
            }


            AudioSource.PlayClipAtPoint(noteSound, Camera.main.transform.position, 1f);
        }