private void LoadLevel(int index) { using (var file = File.OpenRead($"levels/level{index}.png")) { Texture2D map = Texture2D.FromStream(GraphicsDevice, file); gameMap = new Map(map.Width, map.Height, map); } string[] objects = File.ReadAllLines($"levels/level{index}.txt"); foreach (var line in objects) { string[] p = line.Split(' '); if (line.StartsWith("Policeman")) gameMap.AddEntity(new Policeman(gameMap, new Vector(int.Parse(p[1]), int.Parse(p[2])), bool.Parse(p[3]), bool.Parse(p[4]), bool.Parse(p[5]))); else if (line.StartsWith("Patrol")) gameMap.AddEntity(new Policeman(gameMap, new Vector(int.Parse(p[1]), int.Parse(p[2])), int.Parse(p[3]), int.Parse(p[4]), bool.Parse(p[5]), false, false)); else if (line.StartsWith("Civilian")) gameMap.AddEntity(new Civilian(gameMap, new Vector(int.Parse(p[1]), int.Parse(p[2])), bool.Parse(p[3]))); else if (line.StartsWith("Staircase")) gameMap.AddPairOfStairaces(new Vector(int.Parse(p[1]), int.Parse(p[2])), new Vector(int.Parse(p[3]), int.Parse(p[4]))); else if (line.StartsWith("Spawn")) gameMap.Spawn = new Vector(int.Parse(p[1]), int.Parse(p[2])); else if (line.StartsWith("Text")) gameMap.PlayText = true; } gameMap.PlayerEntity.Respawn(); MediaPlayer.Stop(); MediaPlayer.Volume = 0.4f; if (gameMap.PlayText) MediaPlayer.Play(Resources.Audio.CalmMusic); else MediaPlayer.Play(Resources.Audio.IntenseMusic); MediaPlayer.IsRepeating = true; }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); InputHandler.UpdateInternalState(); gameMap?.Update(); if (gameMap?.Won == true) { CurrentLevel++; if (CurrentLevel < 5) LoadLevel(CurrentLevel); else gameMap = null; } base.Update(gameTime); }