public override void LoadContent(ContentManager content) { using (var data = LevelContent.Read(Identifier)) { data.Resolve(Game.GraphicsDevice); foreach (var chunkdata in data.chunks) { Chunk chunk = new Chunk(Game, this, chunkdata); chunk.LoadContent(content); Chunks.Add(chunk); } StartChase = data.startChase; ActiveChunk = Chunks[data.startChunk]; Next = data.next; Name = data.name; TriggeredDialogs = data.storyItems; } for (int i = 0; i < RandomDialogs.Length - 2; ++i) { int newIndex = i + (int)Math.Floor(Game.RNG.NextDouble() * (RandomDialogs.Length - i - 1)); string[] temp = RandomDialogs[i]; RandomDialogs[i] = RandomDialogs[newIndex]; RandomDialogs[newIndex] = temp; } Player.LoadContent(content); Player.Position = ActiveChunk.SpawnPosition; ActiveChunk.Activate(Player); LastActiveChunk = ActiveChunk; // Force camera to be still Camera.Position.X = Player.Position.X; Camera.Position.Y = Player.Position.Y; Camera.UpdateChunk(ActiveChunk); Camera.SnapToLocation(); Camera.Update(); Alarm.LoadContent(content); Game.MusicEngine.Load("Ambient", "future ambient", 12); Game.MusicEngine.Play("Ambient"); Game.SoundEngine.Load("UI_Button"); Game.SoundEngine.Load("Player_WalkieEnd"); Game.SoundEngine.Load("Player_WalkieTalk1"); }
public static LevelContent Read(Stream stream, bool readMetadata = false) { LevelContent content = null; using (var archive = new ZipArchive(stream, ZipArchiveMode.Read)) { // Load base content metadata var entry = archive.GetEntry("level.json"); using (var jsonStream = entry.Open()) using (var reader = new StreamReader(jsonStream)) using (var json = new JsonTextReader(reader)) { content = new JsonSerializer().Deserialize <LevelContent>(json); } MemoryStream readZipEntry(string file) { var localEntry = archive.GetEntry(file); using (var localStream = localEntry.Open()) { var memory = new MemoryStream(); localStream.CopyTo(memory); return(memory); } } // Load texture files if (readMetadata) { if (content.preview != null) { content.previewData = readZipEntry(content.preview); } } else { foreach (var chunk in content.chunks) { foreach (var layer in chunk.layers) { content.textures[layer] = readZipEntry(layer); } } } } return(content); }
private void UpdateLoadName(object identifier) { if (!(RealActiveWindow is LoadScreen)) { return; } if (identifier == null) { ((LoadScreen)RealActiveWindow).LevelName = ""; } else { ((LoadScreen)RealActiveWindow).LevelName = " " + LevelContent.Read(identifier, true).name; } AdvanceLoad(); }