/// <summary> /// Adds a GameObject reference to the Objects dictionary /// If a CollidableObject is passed, it is also added to the CollidableObjects List /// </summary> /// <param name="name">GameObject name</param> /// <param name="g">GameObject reference</param> public static void Add(string name, GameObject g) { Objects.Add(name, g); if (g is CollidableObject) { CollidableObject c = (CollidableObject)g; CollidableObjects.Add(c); NonUIObjects.Add(g); } else if (g is Background) { Background b = (Background)g; Backgrounds.Add(b); } else if (g is UIObject) { UIObject ui = (UIObject)g; UIObjects.Add(ui); } else if (g is SFXWrapper) { SFXWrapper wrap = (SFXWrapper)g; SoundEffects.Add(wrap); } else { NonUIObjects.Add(g); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // Load the object textures into the textures dictionary Textures.Add("Spaceship", this.Content.Load <Texture2D>("Spaceship")); Textures.Add("Bullet", this.Content.Load <Texture2D>("Bullet")); Textures.Add("Rock1", this.Content.Load <Texture2D>("Rock1")); Textures.Add("Rock2", this.Content.Load <Texture2D>("Rock2")); Textures.Add("Rock3", this.Content.Load <Texture2D>("Rock3")); Textures.Add("Star", this.Content.Load <Texture2D>("Star")); Textures.Add("SmokeParticle", this.Content.Load <Texture2D>("SmokeParticle")); // Load fonts Fonts.Add("Miramonte", this.Content.Load <SpriteFont>("Miramonte")); // Load sounds SoundEffects.Add("BulletSound", Content.Load <SoundEffect>("BulletSound")); SoundEffects.Add("HyperspaceOut", Content.Load <SoundEffect>("HyperspaceOut")); SoundEffects.Add("HyperspaceIn", Content.Load <SoundEffect>("HyperspaceIn")); SoundEffects.Add("RockExplosion", Content.Load <SoundEffect>("RockExplosion")); SoundEffects.Add("SpaceshipExplosion", Content.Load <SoundEffect>("SpaceshipExplosion")); SoundEffects.Add("Thruster", Content.Load <SoundEffect>("Thruster")); // Reset the game ResetGame(); }
public static void LoadSfxSound(string sound, string path) { if (SoundEffects == null) { SoundEffects = new Dictionary <string, SoundEffect>(); } SoundEffects.Add(sound, AssetLoader.LoadAsset <SoundEffect>(path)); }
public void PlayFXDirectly(string name) { if (EnableSound) { SoundEffect effect = Global.Content.Load <SoundEffect>(@"SoundFX\" + name); SoundEffectInstance effectInstance = effect.CreateInstance(); effectInstance.Play(); SoundEffects.Add(effectInstance); } }
private static void LoadSoundEffects(ContentManager contentManager) { var directory = $"{contentManager.RootDirectory}\\Game\\Sounds"; var soundFiles = Directory.GetFiles(directory, "*.xnb", SearchOption.AllDirectories) .Select(Path.GetFileNameWithoutExtension) .Select(Path.GetFileName).ToArray(); foreach (var file in soundFiles) { SoundEffects.Add(file, contentManager.Load <SoundEffect>("Game\\Sounds\\" + file)); } }
/// <summary> /// Controls the process of loading the assets from an archive file into memory. This function first determines /// how many assets there are to load. The way it does this is a little juvenile, so I'm sure I'm going to need /// a more sophisticated method for doing this. It's accomplished by performing a LINQ query against the entry /// collection to determine the number of entries that have a file extension. Variable aspects about this are /// currently not considered, such as the kind of extension or the full path of the asset (this one in particular /// would require that the structure of the archive be well defined before hand). /// /// There's another potential caveat here in that numAssetsLoaded is incremented in this method, and is done /// so directly after a call to an asynchronous operation. The increment of this counter may not accurately reflect /// the loading efforts done behind the scenes, and may result in future checks that rely on this measurement to be /// inaccurate. Further testing will need performed to verify that this actually is the case. /// /// While this method is running, the status of its loading can be monitored by calling methods through the public /// properties. There may be a better way of doing this, but like other things, it'll require a bit more /// research. /// /// When this method completes, each asset bank contained in the AssetManager should be populated with the resources /// located within the archive that was provided to this method. /// </summary> /// <param name="archiveFileName">The path to an archive file that contains assets one wishes to load.</param> public void LoadAssets(String archiveFileName) { try { ZipArchive archive = ZipFile.OpenRead(archiveFileName); // I have no idea if this is going to freaking work. numAssetsToLoad = archive.Entries.SelectMany(s => s.Name).Where(s => s.ToString().Split(new Char[] { '.' }).Length > 1).ToList().Count; foreach (ZipArchiveEntry entry in archive.Entries) { String[] fname = entry.Name.Split(new Char[] { '.' }); if (fname.Length > 1) { switch (fname[1]) { case "png": case "jpg": case "jpeg": Textures.Add(fname[0], (CopyAssetMem <Texture>(entry)).Result); //numAssetsLoaded++; break; case "otf": Fonts.Add(fname[0], (CopyAssetMem <Font>(entry)).Result); //numAssetsLoaded++; break; case "ogg": Songs.Add(fname[0], (CopyAssetMem <Music>(entry)).Result); //numAssetsLoaded++; break; case "wav": SoundEffects.Add(fname[0], (CopyAssetMem <SoundBuffer>(entry)).Result); //numAssetsLoaded++; break; default: /* * This could cause a problem where the number of assets to load won't match the expected * amount, and could result in a false positive sent to the caller. In production code, * this would be removed since all kinds of assets would be known and contained in the archive. */ break; } } } } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(-99); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // Load textures Textures.Add("Balloon", Content.Load <Texture2D>("Balloon")); // Load sounds SoundEffects.Add("Pop1", Content.Load <SoundEffect>("Pop1")); SoundEffects.Add("Pop2", Content.Load <SoundEffect>("Pop2")); SoundEffects.Add("Pop3", Content.Load <SoundEffect>("Pop3")); ResetGame(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // Load textures and fonts Textures.Add("Box", Content.Load <Texture2D>("Box")); Fonts.Add("Miramonte", Content.Load <SpriteFont>("Miramonte")); // Load the sound effects SoundEffects.Add("EnergySound", Content.Load <SoundEffect>("EnergySound")); SoundEffects.Add("MagicSpell", Content.Load <SoundEffect>("MagicSpell")); SoundEffects.Add("Motorbike", Content.Load <SoundEffect>("Motorbike")); SoundEffects.Add("Piano", Content.Load <SoundEffect>("Piano")); ResetGame(); }
/// <summary> /// Ctor - Automatically parses a Peppy beatmap /// </summary> public OsuBeatmap(string filePath) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; if (!File.Exists(filePath.Trim())) { IsValid = false; return; } // Create a new beatmap object and default the validity to true. IsValid = true; OriginalFileName = filePath; // This will hold the section of the beatmap that we are parsing. var section = ""; try { foreach (var raw_line in File.ReadAllLines(filePath)) { // Skip empty lines and comments. if (string.IsNullOrWhiteSpace(raw_line) || raw_line.StartsWith("//", StringComparison.Ordinal) || raw_line.StartsWith(" ", StringComparison.Ordinal) || raw_line.StartsWith("_", StringComparison.Ordinal)) { continue; } var line = StripComments(raw_line); switch (line.Trim()) { case "[General]": section = "[General]"; break; case "[Editor]": section = "[Editor]"; break; case "[Metadata]": section = "[Metadata]"; break; case "[Difficulty]": section = "[Difficulty]"; break; case "[Events]": section = "[Events]"; break; case "[TimingPoints]": section = "[TimingPoints]"; break; case "[HitObjects]": section = "[HitObjects]"; break; case "[Colours]": section = "[Colours]"; break; default: break; } // Parse Peppy file format if (line.StartsWith("osu file format")) { PeppyFileFormat = line; } // Parse [General] Section if (section.Equals("[General]")) { if (line.Contains(":")) { var key = line.Substring(0, line.IndexOf(':')); var value = line.Split(':').Last().Trim(); switch (key.Trim()) { case "AudioFilename": AudioFilename = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "AudioLeadIn": AudioLeadIn = int.Parse(value, CultureInfo.InvariantCulture); break; case "PreviewTime": PreviewTime = int.Parse(value, CultureInfo.InvariantCulture); break; case "Countdown": Countdown = int.Parse(value, CultureInfo.InvariantCulture); break; case "SampleSet": SampleSet = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value));; break; case "StackLeniency": StackLeniency = float.Parse(value, CultureInfo.InvariantCulture); break; case "Mode": Mode = int.Parse(value, CultureInfo.InvariantCulture); if (Mode != 3) { IsValid = false; } break; case "LetterboxInBreaks": LetterboxInBreaks = int.Parse(value, CultureInfo.InvariantCulture); break; case "SpecialStyle": SpecialStyle = int.Parse(value, CultureInfo.InvariantCulture); break; case "WidescreenStoryboard": WidescreenStoryboard = int.Parse(value, CultureInfo.InvariantCulture); break; } } } // Parse [Editor] Data if (section.Equals("[Editor]")) { if (line.Contains(":")) { var key = line.Substring(0, line.IndexOf(':')); var value = line.Split(':').Last(); switch (key.Trim()) { case "Bookmarks": Bookmarks = value; break; case "DistanceSpacing": DistanceSpacing = float.Parse(value, CultureInfo.InvariantCulture); break; case "BeatDivisor": BeatDivisor = int.Parse(value, CultureInfo.InvariantCulture); break; case "GridSize": GridSize = int.Parse(value, CultureInfo.InvariantCulture); break; case "TimelineZoom": TimelineZoom = float.Parse(value, CultureInfo.InvariantCulture); break; } } } // Parse [Metadata] Data if (section.Equals("[Metadata]")) { if (line.Contains(":")) { var key = line.Substring(0, line.IndexOf(':')); var value = line.Substring(line.IndexOf(':') + 1); switch (key.Trim()) { case "Title": Title = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "TitleUnicode": TitleUnicode = value; break; case "Artist": Artist = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "ArtistUnicode": ArtistUnicode = value; break; case "Creator": Creator = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "Version": Version = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "Source": Source = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "Tags": Tags = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value)); break; case "BeatmapID": BeatmapID = int.Parse(value, CultureInfo.InvariantCulture); break; case "BeatmapSetID": BeatmapSetID = int.Parse(value, CultureInfo.InvariantCulture); break; default: break; } } } // Parse [Difficulty] Data if (section.Equals("[Difficulty]")) { if (line.Contains(":")) { var key = line.Substring(0, line.IndexOf(':')); var value = line.Split(':').Last(); switch (key.Trim()) { case "HPDrainRate": HPDrainRate = float.Parse(value, CultureInfo.InvariantCulture); break; case "CircleSize": KeyCount = int.Parse(value, CultureInfo.InvariantCulture); if (KeyCount != 4 && KeyCount != 7 && KeyCount != 5 && KeyCount != 8) { IsValid = false; } break; case "OverallDifficulty": OverallDifficulty = float.Parse(value, CultureInfo.InvariantCulture); break; case "ApproachRate": ApproachRate = float.Parse(value, CultureInfo.InvariantCulture); break; case "SliderMultiplier": SliderMultiplier = float.Parse(value, CultureInfo.InvariantCulture); break; case "SliderTickRate": SliderTickRate = float.Parse(value, CultureInfo.InvariantCulture); break; } } } // Parse [Events] Data if (section.Equals("[Events]")) { var values = line.Split(','); // Background if (line.ToLower().Contains("png") || line.ToLower().Contains("jpg") || line.ToLower().Contains("jpeg")) { Background = values[2].Replace("\"", ""); } // Sound effects if (values[0] == "Sample" || values[0] == "5") { var path = values[3].Trim('"').Replace(Path.DirectorySeparatorChar, '/'); SoundEffects.Add(new OsuSampleInfo() { StartTime = int.Parse(values[1]), Layer = int.Parse(values[2]), Volume = Math.Max(0, Math.Min(100, values.Length >= 5 ? int.Parse(values[4], CultureInfo.InvariantCulture) : 100)), Sample = CustomAudioSampleIndex(path) }); } } try { // Parse [TimingPoints] Data if (section.Equals("[TimingPoints]")) { if (line.Contains(",")) { var values = line.Split(','); // Parse as double because there are some maps which have this value too large to fit in // a float, for example https://osu.ppy.sh/beatmapsets/681731#mania/1441497. Parsing as // double and then casting to float results in the correct outcome though. var msecPerBeat = double.Parse(values[1], CultureInfo.InvariantCulture); var timingPoint = new OsuTimingPoint { Offset = float.Parse(values[0], CultureInfo.InvariantCulture), MillisecondsPerBeat = (float)msecPerBeat, Signature = values[2][0] == '0' ? TimeSignature.Quadruple : (TimeSignature)int.Parse(values[2], CultureInfo.InvariantCulture), SampleType = int.Parse(values[3], CultureInfo.InvariantCulture), SampleSet = int.Parse(values[4], CultureInfo.InvariantCulture), Volume = Math.Max(0, int.Parse(values[5], CultureInfo.InvariantCulture)), Inherited = int.Parse(values[6], CultureInfo.InvariantCulture), KiaiMode = int.Parse(values[7], CultureInfo.InvariantCulture) }; TimingPoints.Add(timingPoint); } } } catch (Exception e) { IsValid = false; } // Parse [HitObjects] Data if (section.Equals("[HitObjects]")) { if (line.Contains(",")) { var values = line.Split(','); // We'll need to parse LNs differently than normal HitObjects, // as they have a different syntax. 128 in the object's type // signifies that it is an LN var osuHitObject = new OsuHitObject { X = int.Parse(values[0], CultureInfo.InvariantCulture), Y = int.Parse(values[1], CultureInfo.InvariantCulture), StartTime = int.Parse(values[2], CultureInfo.InvariantCulture), Type = (HitObjectType)int.Parse(values[3], CultureInfo.InvariantCulture), HitSound = (HitSoundType)int.Parse(values[4], CultureInfo.InvariantCulture), Additions = "0:0:0:0:", KeySound = -1 }; // If it's an LN, we'll want to add the object's EndTime as well. if (osuHitObject.Type.HasFlag(HitObjectType.Hold)) { var endTime = values[5].Substring(0, values[5].IndexOf(":", StringComparison.Ordinal)); osuHitObject.EndTime = int.Parse(endTime, CultureInfo.InvariantCulture); } // Parse the key sound. if (values.Length > 5) { var additions = values[5].Split(':'); var volumeField = osuHitObject.Type.HasFlag(HitObjectType.Hold) ? 4 : 3; if (additions.Length > volumeField && additions[volumeField].Length > 0) { osuHitObject.Volume = Math.Max(0, int.Parse(additions[volumeField], CultureInfo.InvariantCulture)); } var keySoundField = volumeField + 1; if (additions.Length > keySoundField && additions[keySoundField].Length > 0) { osuHitObject.KeySound = CustomAudioSampleIndex(additions[keySoundField]); } } HitObjects.Add(osuHitObject); } } } } catch (Exception e) { IsValid = false; } }
public override void LoadSoundEffects() { SoundEffects.Add("Explosion", Game.Content.Load <SoundEffect>(@"Sounds\Explosion")); Components.GetSingle <SoundService>().LoadContent(SoundEffects); }