Exemplo n.º 1
0
        public async Task <bool> GenerateNoteSequence(int musicMode)
        {
            //load available punching notes
            PunchKeySotrageManager punchStorageManager = new PunchKeySotrageManager();
            NoteLibrary            availableNotebrary  = await punchStorageManager.LoadNoteLibrary();

            List <int>[] noteArray = new List <int>[4] {
                new List <int>(), new List <int>(), new List <int>(), new List <int>()
            };                                                                                                               //indexing -> 0 : 1 key----1: 2 key----2: 3 key----3: 4 key

            foreach (Note note in availableNotebrary.noteLibrary)
            {
                int difficulty = note.serPunchingJoints.Count - 1;
                if (difficulty >= 0 && difficulty < 4)
                {
                    noteArray[difficulty].Add(note.noteId);
                }
            }

            //difficulty probability array
            int[] difficultyProbability;
            PunchKeyMode = musicMode;
            switch (PunchKeyMode)
            {
            case (int)Music.MusicMode.Exercise:
                difficultyProbability = new int[5] {
                    50, 35, 10, 5, 65
                };
                break;

            case (int)Music.MusicMode.EasyChallenge:
                difficultyProbability = new int[5] {
                    65, 35, 5, 0, 60
                };
                break;

            case (int)Music.MusicMode.NormalChallenge:
                difficultyProbability = new int[5] {
                    35, 50, 10, 5, 45
                };
                break;

            case (int)Music.MusicMode.HardChallenge:
                difficultyProbability = new int[5] {
                    25, 55, 10, 10, 30
                };
                break;

            default:
                difficultyProbability = new int[5];
                break;
            }
            //Generate sequence based on probability
            NoteSequence = new List <int>();
            for (int i = 0; i < Definitions.temporaryNoteLenght; i++)
            {
                //create distribution function
                int rnd = fastRandom(i, 1, 100);
                int cummuativeDistribution = 0;
                for (int j = 0; j < noteArray.Length; j++)
                {
                    cummuativeDistribution += difficultyProbability[j]; //kumulatif cuma dari index 0 sampai 3, 1note, 2note, 3note, 4note
                    if (rnd < cummuativeDistribution)
                    {
                        if (j > 2)
                        {
                            NoteSequence.Add(0);
                        }
                        NoteSequence.Add((noteArray[j])[fastRandom(i + j, 0, noteArray[j].Count)]);     //random dari daftar note sesuai kumulatif
                        break;
                    }
                }

                //create break function
                rnd = fastRandom(i, 1, 100);
                if (rnd < difficultyProbability[4])
                {
                    NoteSequence.Add(0);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private async void GameStart()
        {
            App.ToggleKinectControl(false);

            //timing system
            startGameTimeSpan = DateTime.Now.TimeOfDay;
            runningGameTime   = 0;
            pausedGameTime    = 0;

            //punching system
            punchManager.activeMusicBPM    = activeMusic.musicBPM;
            punchManager.activeNoteLibrary = await punchKeyStorageManager.LoadNoteLibrary();

            int selectedNoteIndex = (int)activeMusic.selectedMusicMode;

            //HACK copy challenge note to multiplayer note
            if (activeMusic.selectedMusicMode == Music.MusicMode.EasyMultiplayer)
            {
                selectedNoteIndex = (int)Music.MusicMode.EasyChallenge;
            }
            else if (activeMusic.selectedMusicMode == Music.MusicMode.NormalMultiplayer)
            {
                selectedNoteIndex = (int)Music.MusicMode.NormalChallenge;
            }
            else if (activeMusic.selectedMusicMode == Music.MusicMode.HardMultiplayer)
            {
                selectedNoteIndex = (int)Music.MusicMode.HardChallenge;
            }
            punchManager.activeNoteSequence = activeMusic.musicPunchKey[selectedNoteIndex].NoteSequence;

            //Music System
            BGMPlayer.MediaEnded += MusicEnded;
            BGMPlayer.IsLooping   = false;
            VolumeSlider.Value    = (int)(Definitions.musicVolume * 10);
            activeMusic.setMusicController(BGMPlayer);
            await activeMusic.LoadExistingAsync();

            activeMusic.Play();

            //sfx system
            SFXPlayer.Volume    = Definitions.sfxVolume;
            SFXPlayer.IsLooping = false;

            //scoring
            if (selectedGameMode != MusicSelect.GameMode.Multiplayer)
            {
                highScore = activeMusic.musicPunchKey[(int)activeMusic.selectedMusicMode].punchKeyHighScore;
            }

            //avatars
            foreach (var avaImage in activePlayer[0].activeAvatar.avaImages)
            {
                gameCanvas.Children.Add(avaImage);
            }

            if (selectedGameMode == MusicSelect.GameMode.Multiplayer)
            {
                foreach (var avaImage in activePlayer[1].activeAvatar.avaImages)
                {
                    gameCanvas.Children.Add(avaImage);
                }
            }


            gameState = GameState.Play;
        }