protected override void OnDraw(GameTime gameTime) { if (DisplayGeometry) { TiledPlatformerGeometry Geometry = (TiledPlatformerGeometry)CorvusGame.Instance.SceneManager.ActiveScene.Geometry; foreach (TiledPlatformerGeometryObject GeometryObj in Geometry.GeometryObjects) { CorvusGame.Instance.SpriteBatch.Draw(GeometryTexture, Camera.Active.WorldToScreen(GeometryObj.Location), new Color(255, 0, 0, 64)); } } if (DisplayEntities) { foreach (var Entity in SceneManager.ActiveScene.Entities) { CorvusGame.Instance.SpriteBatch.Draw(GeometryTexture, Camera.Active.WorldToScreen(Entity.Location), new Color(0, 0, 255, 64)); } } if (DisplayPerformance) { CorvusGame.Instance.SpriteBatch.DrawString(Font, "FPS: " + CorvusGame.Instance.FPS, new Vector2(10, CorvusGame.Instance.GraphicsDevice.Viewport.Height - 30), Color.Yellow); if (CorvusGame.Instance.Players.Any()) { CorvusGame.Instance.SpriteBatch.DrawString(Font, "Center: " + CorvusGame.Instance.Players.First().Character.Location.Center, new Vector2(10, CorvusGame.Instance.GraphicsDevice.Viewport.Height - 50), Color.Yellow); } string GenText = "Garbage Collections Per Generation - "; for (int i = 0; i <= GC.MaxGeneration; i++) { GenText += "{" + i + ", " + GC.CollectionCount(i) + "} "; } CorvusGame.Instance.SpriteBatch.DrawString(Font, GenText, new Vector2(10, CorvusGame.Instance.GraphicsDevice.Viewport.Height - 70), Color.Yellow); } }
/// <summary> /// Changes the scene to the Scene with the specified name. /// If the Scene has already been loaded, it will reuse that instance of the scene. /// Otherwise, the Scene will be loaded. /// </summary> public CorvusScene ChangeScene(string LevelName, bool ResetPlayers, string spawnId = "StartPoint") { // TODO: Refactor this. var Scene = ActiveScenes.FirstOrDefault(c => c.Name.Equals(LevelName, StringComparison.InvariantCultureIgnoreCase)); if (Scene == null) { Scene = CorvusScene.Load(LevelName); Scene.Disposed += Scene_Disposed; ActiveScenes.Add(Scene); Scene.AddSystem(new PhysicsSystem()); //This is likely a shitty idea for obvious reasons, but still works. if (Scene.Name.Contains("Arena")) { Scene.AddSystem(new ArenaSystem()); } TiledPlatformerGeometry Geometry = new TiledPlatformerGeometry(Scene); Scene.Initialize(Geometry); this.AddComponent(Scene); this.AddComponent(new Corvus.Interface.InGameInterface(Scene.GameState)); } var OldScene = _ActiveScene; if (OldScene == Scene) { return(Scene); } _ActiveScene = Scene; if (SceneChanged != null) { SceneChanged(OldScene, _ActiveScene); } if (OldScene != null) { OldScene.Visible = false; OldScene.Enabled = false; } ActiveScene.Visible = true; ActiveScene.Enabled = true; foreach (CorvusPlayer Player in CorvusGame.Instance.Players) { if (Player.Character != null) { if (ResetPlayers) { Player.ResetCharacter(); } else if (!Player.Character.IsDisposed) // Dispose it to transfer to a new Scene. { Player.Character.Dispose(); } var Position = Player.Character.Position; ActiveScene.AddEntity(Player.Character); Player.Character.Position = Position; // Keep them at their old position. } } //Plays the song. if (Scene.Properties.Any()) { foreach (LevelProperty p in Scene.Properties) { if (p.Name.Equals("Audio", StringComparison.InvariantCultureIgnoreCase)) { var songProperties = p.Value.Split(','); if (songProperties.Length >= 1 && string.IsNullOrEmpty(songProperties[0])) { CorvEngine.AudioManager.StopMusic(); //Stops the song continue; } else if (songProperties.Length != 3) { throw new ArgumentException("Expected three arguments for Audio, being the song name, fade duration, and volume. Ex:(SongName1, 2, 0.5)"); } string songName = songProperties[0]; float fadeDuration = float.Parse(songProperties[1]); float volume = float.Parse(songProperties[2]); CorvEngine.AudioManager.PlayMusic(songName, fadeDuration); CorvEngine.AudioManager.SetMusicVolume(volume); } } } //Set SpawnPoint. var spawnPoint = Scene.Entities.FirstOrDefault(c => c.Name == spawnId); if (spawnPoint == null) { throw new ArgumentException("A spawn point with the ID '" + spawnId + "' does not exist."); } if (Scene.Engine.Players.Count() != 0) { foreach (var player in Scene.Engine.Players) { var playerEntity = player.Character; if (spawnPoint != null) { playerEntity.Position = spawnPoint.Position; } } } return(_ActiveScene); }