Ejemplo n.º 1
0
        /// <summary>
        /// Inicia o Game
        /// </summary>
        public virtual void IniciarJogo(List <PositionTemplate> userPositions)
        {
            Game.State = GameStateEnum.Running;

            //Teste
            GameSong.Start();
        }
Ejemplo n.º 2
0
        private static void GenerateBPMChangeNotes(GameSong song, Beatline bl)
        {
            double prev = song.BPMs[0.0];

            foreach (double bpmKey in song.BPMs.Keys)
            {
                //Don't mark the starting BPM as a BPM change.
                if (bpmKey == 0.0)
                {
                    continue;
                }

                //Don't mark a BPM change if there isn't actually a change in the BPM.
                if (song.BPMs[bpmKey] == prev)
                {
                    continue;
                }

                var noteType = song.BPMs[bpmKey] > prev
                                   ? BeatlineNoteType.BPMIncrease
                                   : BeatlineNoteType.BPMDecrease;


                bl.InsertBeatlineNote(new BeatlineNote {
                    NoteType = noteType, Position = bpmKey
                }, 0);

                prev = song.BPMs[bpmKey];
            }
        }
Ejemplo n.º 3
0
        private void GenerateStandardNotes(GameSong song, Beatline bl)
        {
            // Add a beatline note for every phrase (4 beats), unless its listed in the
            // RemoveNotes or SuperNotes collection.
            for (int beat = 0; beat < song.GetEndingTimeInPhrase(); beat++)
            {
                if (song.RemoveNotes.Contains(beat))
                {
                    continue;
                }
                if (song.SuperNotes.Contains(beat))
                {
                    continue;
                }
                bl.AddBeatlineNote(new BeatlineNote {
                    Position = beat
                });
            }

            foreach (var pos in song.AddNotes)
            {
                bl.AddBeatlineNote(new BeatlineNote {
                    Position = pos
                });
            }

            foreach (var pos in song.SuperNotes)
            {
                bl.AddBeatlineNote(new BeatlineNote {
                    Position = pos, NoteType = BeatlineNoteType.Super
                });
            }
        }
Ejemplo n.º 4
0
        private void AdjustBpmChanges(GameSong song, int idx)
        {
            var newBPMs = new Dictionary <double, double>();

            foreach (double key in song.BPMs.Keys)
            {
                if (key == 0.0)
                {
                    newBPMs[key] = song.BPMs[key];
                }
                else
                {
                    newBPMs[key - idx] = song.BPMs[key];
                }
            }
            song.BPMs = newBPMs;

            var newStops = new Dictionary <double, double>();

            foreach (double key in song.Stops.Keys)
            {
                newStops[key - idx] = song.Stops[key];
            }
            song.Stops = newStops;
        }
Ejemplo n.º 5
0
        private void CalculateLength(GameSong song, string notes)
        {
            var endPhrase = ParseNoteString(notes, false);

            song.Length = song.ConvertPhraseToMS(endPhrase + 0.5) / 1000.0;
            Log.AddMessage(String.Format("Song notes end at phrase {0}. Length set to {1}. ", endPhrase, song.Length), LogLevel.DEBUG);
        }
Ejemplo n.º 6
0
        private string SaveSongNotes(GameSong song)
        {
            var result = "";

            if (song.AddNotes.Count > 0)
            {
                result += "AddNotes=";
                result  = song.AddNotes.Aggregate(result, (current, note) => current + string.Format("{0:F3},", note));
                result  = result.TrimEnd(',');
                result += ";\n";
            }

            if (song.RemoveNotes.Count > 0)
            {
                result += "RemoveNotes=";
                result  = song.RemoveNotes.Aggregate(result, (current, note) => current + string.Format("{0:F3},", note));
                result  = result.TrimEnd(',');
                result += ";\n";
            }
            if (song.SuperNotes.Count > 0)
            {
                result += "SuperNotes=";
                result  = song.SuperNotes.Aggregate(result, (current, note) => current + string.Format("{0:F3},", note));
                result  = result.TrimEnd(',');
                result += ";\n";
            }
            return(result);
        }
Ejemplo n.º 7
0
 private void GenerateSongEndNote(GameSong song, Beatline bl)
 {
     bl.AddBeatlineNote(new BeatlineNote
     {
         NoteType = BeatlineNoteType.EndOfSong,
         Position = song.GetEndingTimeInPhrase()
     });
 }
Ejemplo n.º 8
0
        private void AdjustOffset(GameSong song, string notes)
        {
            var startPhrase = ParseNoteString(notes, true);

            song.Offset = song.ConvertPhraseToMS(startPhrase) / 1000.0;
            AdjustBpmChanges(song, startPhrase);
            Log.AddMessage(String.Format("Song notes start at phrase {0}. Offset set to {1}. ", startPhrase, song.Offset), LogLevel.DEBUG);
        }
Ejemplo n.º 9
0
 private static void GenerateStopNotes(GameSong song, Beatline bl)
 {
     foreach (var stopKey in song.Stops.Keys)
     {
         bl.InsertBeatlineNote(
             new BeatlineNote {
             NoteType = BeatlineNoteType.Stop, Position = stopKey
         }, 0);
     }
 }
Ejemplo n.º 10
0
        private string SaveSongBackground(GameSong song)
        {
            var result = "Background=";

            if (String.IsNullOrEmpty(song.BackgroundFile))
            {
                return("");
            }

            result += song.BackgroundFile + ";";
            return(result);
        }
Ejemplo n.º 11
0
        public void ResumirJogo()
        {
            Game.State = GameStateEnum.Running;

            //Teste
            GameSong.Start();

            if (Animation == null)
            {
                return;
            }

            Animation?.Resume();
        }
Ejemplo n.º 12
0
        private string SaveSongBPMs(GameSong song)
        {
            var result = "Bpm=";

            foreach (double key in song.BPMs.Keys)
            {
                result += Math.Round(key, 3).ToString(CultureInfo.InvariantCulture);
                result += ":" + Math.Round(song.BPMs[key], 3).ToString(CultureInfo.InvariantCulture);
                result += ",";
            }
            result  = result.TrimEnd(',');
            result += ";";
            return(result);
        }
Ejemplo n.º 13
0
        public void PausarJogo()
        {
            Game.State = GameStateEnum.Paused;

            //Teste
            GameSong.Pause();

            if (Animation == null)
            {
                return;
            }

            Animation?.Pause();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Finaliza as referêncais removendo os objetos linkados da memória
        /// </summary>
        public bool Finalizar()
        {
            Game.State = GameStateEnum.Finished;
            Central.Dispose();

            DesabilitarValidacao(ValidacaoEnum.FINALIZADO);
            Game.RemoverRastreadores();

            Animation?.Finish();

            //Teste
            GameSong?.Finalizar();

            return(true);
        }
Ejemplo n.º 15
0
        public override GameSong LoadFromFile(string filename, out bool valid)
        {
            _newSong = new GameSong {
                ReadOnly = true
            };
            _newSong.BPMs = new Dictionary <double, double>();
            Log.AddMessage("Converting DWI File: " + filename, LogLevel.NOTE);

            try
            {
                string songText = File.ReadAllText(filename);
                ParseText(songText);

                var selectedNotes = (from e in _notes where e != null select e).First();

                _newSong.Offset += OffsetAdjust;

                CalculateLength(_newSong, selectedNotes);
                _newSong.Length += OffsetAdjust;

                //Length calculation needs the ORIGINAL offset, so this must be done after it.
                AdjustOffset(_newSong, selectedNotes);

                _newSong.Path           = Path.GetDirectoryName(filename);
                _newSong.DefinitionFile = Path.GetFileName(filename);

                if ((String.IsNullOrEmpty(_newSong.AudioFile)))
                {
                    _newSong.AudioFile = FindUndefinedAudioFile(_newSong.Path, _newSong.DefinitionFile);
                }
                _newSong.SetMD5();

                if (ConvertToSNG)
                {
                    _newSong.ReadOnly = false;
                    SaveToFile(_newSong);
                }
                valid = true;
            }
            catch (Exception ex)
            {
                Log.AddException(ex);
                Log.AddMessage("Failed to load DWI File: " + ex.Message, LogLevel.WARN);
                valid = false;
            }

            return(_newSong);
        }
Ejemplo n.º 16
0
 public void AddTimingPointMarkers(GameSong song)
 {
     for (int index = 0; index < _beatlines.Length; index++)
     {
         if (!Players[index].Playing)
         {
             continue;
         }
         AddNotes.AddRange(song.AddNotes);
         var bl = _beatlines[index];
         GenerateStandardNotes(song, bl);
         GenerateSongEndNote(song, bl);
         GenerateBPMChangeNotes(song, bl);
         GenerateStopNotes(song, bl);
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Reseta o Game
        /// </summary>
        public virtual void ResetarJogo()
        {
            Game.CurrentIndex = 0;

            foreach (var val in Game.Validacoes)
            {
                val.IniciarValidacao();
            }

            if (Animation.State == StoryboardState.Paused)
            {
                Animation?.Finish();
            }

            //Teste
            GameSong.Randomize();
        }
Ejemplo n.º 18
0
        private string SaveSongStops(GameSong song)
        {
            if (song.Stops.Keys.Count <= 0)
            {
                return("");
            }
            var result = "Stops=";

            foreach (double key in song.Stops.Keys)
            {
                result += Math.Round(key, 3).ToString(CultureInfo.InvariantCulture);
                result += ":" + Math.Round(song.Stops[key], 3).ToString(CultureInfo.InvariantCulture);
                result += ",";
            }
            result  = result.TrimEnd(',');
            result += ";";
            return(result);
        }
Ejemplo n.º 19
0
        private void CalculateLength(GameSong song, string notes)
        {
            var lines = notes.Split(',');
            var idx   = 0;

            for (int x = lines.Length - 1; x >= 0; x--)
            {
                //Extension method
                if (lines[x].ToCharArray().ContainsAny('1', '2'))
                {
                    idx = x;
                    break;
                }
            }

            song.Length = song.ConvertPhraseToMS(idx + 0.5) / 1000.0;
            Log.AddMessage(String.Format("Song notes end at phrase {0}. Length set to {1}. ", idx, song.Length), LogLevel.DEBUG);
        }
Ejemplo n.º 20
0
        public override void Load()
        {
            switch (GameManager.selectedSongID)
            {
            case MainGame.Gameplay.SongID.OneMustVibe:
                thisSong = new Song_OneMustVibe(Vector2.Zero);
                break;

            case MainGame.Gameplay.SongID.Shmovement:
                thisSong = new Song_Shmovement(Vector2.Zero);
                break;
            }
            gameObjects.Add(thisSong);
            thisSong.LoadContent(thisContent);

            TimeSpan bufferTest = TimeSpan.FromSeconds(0);

            MediaPlayer.Play(thisSong.song, bufferTest);
        }
Ejemplo n.º 21
0
        private void AdjustOffset(GameSong song, string notes)
        {
            var lines = notes.Split(',');
            var idx   = 0;

            for (int x = 0; x < lines.Length; x++)
            {
                //Extension method
                if (lines[x].ToCharArray().ContainsAny('1', '2'))
                {
                    idx = x;
                    break;
                }
            }
            song.Offset = song.ConvertPhraseToMS(idx) / 1000.0;

            //Adjust all BPM changes forward to compensate for the offset moving.
            AdjustBpmChanges(song, idx);
            Log.AddMessage(String.Format("Song notes start at phrase {0}. Offset set to {1}. ", idx, song.Offset), LogLevel.DEBUG);
        }
Ejemplo n.º 22
0
        public void SaveToFile(GameSong song)
        {
            if (song.ReadOnly)
            {
                return;
            }

            song.DefinitionFile = Path.GetFileNameWithoutExtension(song.DefinitionFile) + ".sng";

            var file = new FileStream(song.Path + "\\" + song.DefinitionFile, FileMode.Create, FileAccess.Write);
            var sw   = new StreamWriter(file);

            sw.WriteLine("#SONG-1.1;");
            sw.WriteLine("Title={0};", song.Title);
            sw.WriteLine("Subtitle={0};", song.Subtitle);
            sw.WriteLine("Artist={0};", song.Artist);

            sw.WriteLine(SaveSongBPMs(song));
            sw.WriteLine("Offset={0};", Math.Round(song.Offset, 3).ToString(CultureInfo.InvariantCulture));
            sw.WriteLine("AudioStart={0};", Math.Round(song.AudioStart, 3).ToString(CultureInfo.InvariantCulture));
            sw.WriteLine("Length={0};", Math.Round(song.Length, 3).ToString(CultureInfo.InvariantCulture));
            sw.WriteLine("AudioFile={0};", song.AudioFile);
            sw.WriteLine("AudioFileMD5={0};", song.AudioFileMD5);

            if (song.RequiredLevel > 1)
            {
                sw.WriteLine("RequiredLevel={0};", song.RequiredLevel);
            }

            sw.WriteLine(SaveSongStops(song));
            sw.WriteLine(SaveSongBackground(song));
            sw.WriteLine(SaveSongNotes(song));
            sw.Close();

            Log.AddMessage(String.Format("Song file saved successfully: {0}\\{1}", song.Path, song.DefinitionFile), LogLevel.INFO);
        }
Ejemplo n.º 23
0
        public override GameSong LoadFromFile(string filename, out bool valid)
        {
            _newSong                = GameSong.LoadDefaults();
            _newSong.Path           = filename.Substring(0, filename.LastIndexOf("\\"));
            _newSong.DefinitionFile = Path.GetFileName(filename);
            try
            {
                string songText = File.ReadAllText(filename);

                songText = songText.Replace("\r", "");
                songText = songText.Replace("\n", "");

                string[] rules = songText.Split(';');

                if (!rules[0].StartsWith("#SONG"))
                {
                    throw new Exception("Song is not a valid song file. It must start with #SONG- followed by the version number.");
                }
                var songVersion = rules[0].Substring(rules[0].IndexOf("-") + 1);

                foreach (string rule in rules)
                {
                    if ((rule.Length == 0) || (rule[0] == '#'))
                    {
                        continue;
                    }

                    string field = rule.Substring(0, rule.IndexOf("=")).ToUpper();
                    string value = rule.Substring(rule.IndexOf("=") + 1);

                    switch (field.ToUpper())
                    {
                    case "TITLE":
                        _newSong.Title = value;
                        break;

                    case "SUBTITLE":
                        _newSong.Subtitle = value;
                        break;

                    case "ARTIST":
                        _newSong.Artist = value;
                        break;

                    case "OFFSET":
                        _newSong.Offset = Convert.ToDouble(value, CultureInfo.InvariantCulture.NumberFormat);
                        break;

                    case "AUDIOSTART":
                        _newSong.AudioStart = Convert.ToDouble(value, CultureInfo.InvariantCulture.NumberFormat);
                        break;

                    case "LENGTH":
                        _newSong.Length = Convert.ToDouble(value, CultureInfo.InvariantCulture.NumberFormat);
                        break;

                    case "BPM":
                        switch (songVersion)
                        {
                        case "1.0":
                            _newSong.StartBPM = Convert.ToDouble(value, CultureInfo.InvariantCulture.NumberFormat);
                            break;

                        case "1.1":
                            ParseBPMs(value);
                            break;
                        }
                        break;

                    case "SONGFILE":
                    case "AUDIOFILE":
                        _newSong.AudioFile = value;
                        break;

                    case "SONGFILEMD5":
                    case "AUDIOFILEMD5":
                        _newSong.AudioFileMD5 = value;
                        break;

                    case "STOPS":
                        ParseStops(value);
                        break;

                    case "BACKGROUND":
                        _newSong.BackgroundFile = value;
                        break;

                    case "REQUIREDLEVEL":
                        _newSong.RequiredLevel = Convert.ToInt32(value);
                        break;

                    case "ADDNOTES":
                        _newSong.AddNotes = ToDoubleArray(value.Split(','));
                        break;

                    case "REMOVENOTES":
                        _newSong.RemoveNotes = ToDoubleArray(value.Split(','));
                        break;

                    case "SUPERNOTES":
                        _newSong.SuperNotes = ToDoubleArray(value.Split(','));
                        break;
                    }
                }

                if (String.IsNullOrEmpty(_newSong.AudioFile))
                {
                    _newSong.AudioFile = FindUndefinedAudioFile(_newSong.Path, _newSong.DefinitionFile);
                }
                valid = true;
            }
            catch (Exception ex)
            {
                Log.AddException(ex);
                LastLoadError = ex.Message;
                Log.AddMessage("Failed to load song: " + ex.Message + " File: " + filename, LogLevel.WARN);
                valid = false;
            }

            return(_newSong);
        }
Ejemplo n.º 24
0
        public override void Initialize()
        {
            _gameSong = (GameSong)Core.Cookies["CurrentSong"];
            var currentGameType = (GameType)Core.Cookies["CurrentGameType"];

            _performanceBar = new PerformanceBar
            {
                Metrics = Core.Metrics, Players = Core.Players, GameType = currentGameType
            };
            _performanceBar.SetPosition();


            _lifeBarSet = new LifeBarSet(Core.Metrics, Core.Players, currentGameType);
            _lifeBarSet.BlazingEnded += ((sender, e) => _noteBarSet.CancelReverse((int)e.Object));

            _levelbarSet                   = new LevelBarSet(Core.Metrics, Core.Players, currentGameType);
            _hitsBarSet                    = new HitsBarSet(Core.Metrics, Core.Players, currentGameType);
            _scoreSet                      = new ScoreSet(Core.Metrics, Core.Players, currentGameType);
            _noteJudgementSet              = new NoteJudgementSet(Core.Metrics, Core.Players, currentGameType, _lifeBarSet, _scoreSet);
            _countdownSet                  = new CountdownSet(Core.Metrics, Core.Players, currentGameType);
            _beatlineSet                   = new BeatlineSet(Core.Metrics, Core.Players, currentGameType);
            _gmBarSet                      = new GrooveMomentumBarSet(Core.Metrics, Core.Players, currentGameType);
            _hitAggregator                 = new BeatlineHitAggregator(Core.Players, currentGameType);
            _hitAggregator.HitsAggregated += HitsAggregated;
            _noteBarSet                    = new NoteBarSet(Core.Metrics, Core.Players, currentGameType);
            _noteBarSet.PlayerFaulted     += (PlayerFaulted);
            _noteBarSet.PlayerArrowHit    += (PlayerArrowHit);
            _songTimeLine                  = new SongTimeLine {
                Position = Core.Metrics["MainGameSongTimeline", 0], Size = Core.Metrics["MainGameSongTimeline.Size", 0]
            };

            _beatlineSet.NoteMissed += BeatlineNoteMissed;
            _beatlineSet.CPUNoteHit += BeatlineNoteCPUHit;
            _recordReplayer          = new RecordReplayer(currentGameType);
            _recordReplayer.LoadRecord(_gameSong.GetHashCode(), currentGameType);
            _recordReplayer.Position = Core.Metrics["RecordReplayer", GetFreeLocation()];
            _recordReplayer.Size     = Core.Metrics["RecordReplayer.Size", 0];
            _displayState            = 0;
            _songLoadDelay           = 0.0;
            _lastLifeRecord          = 0.5;
            _lastUpdate = 0.0;

            for (int x = 0; x < PLAYER_COUNT; x++)
            {
                _lifeBarSet.Reset();
                Core.Players[x].ResetStats();
            }
            _noteBarSet.InitNoteBars();



            _startTime = null;
            _dspActive = false;
            _panic     = Core.Cookies.ContainsKey("Panic");
            _beatlineSet.EndingPhrase = _gameSong.GetEndingTimeInPhrase();
            _beatlineSet.Bpm          = _gameSong.CurrentBPM(0.0);
            _beatlineSet.AddTimingPointMarkers(_gameSong);
            _beatlineSet.SetSpeeds();
            _noteBarSet.Visible = true;
            _visualBackground   = new VisualizerBackground
            {
                Size          = Core.Metrics["VisualizerBackground.Size", 0],
                AudioManager  = Core.Audio,
                Position      = Core.Metrics["VisualizerBackground", 0],
                SongChannel   = (int)Core.Cookies["GameSongChannel"],
                MaxBrightness = Convert.ToByte(Core.Settings["BackgroundAnimation"])
            };
            InitSprites();

            base.Initialize();
        }