// Object Function Declaration /// <summary> /// The constructor for the Level class. Basically doesn't do anything /// important at this point. /// </summary> public Level(GraphicsDevice graphicsDevice) { this.entities = new Dictionary<string, Entity>(); this.addList = new Dictionary<string, Entity>(); this.removeList = new List<string>(); this.Camera = new Camera(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height); this.screenRect = Rectangle.Empty; this.levelStart = true; this.levelPlaying = true; this.dialogueManager = null; }
/// <summary> /// Loads the level from a descriptive script file on the harddrive. /// </summary> public void Load(string newLevel, string oldLevel, Pantheon gameReference) { levelMap = gameReference.Content.Load<Map>(newLevel); levelNum = newLevel; this.entities.Add("character", gameReference.player); this.entities["character"].Load(gameReference.Content); // If the dialogue manager doesn't exist, create it. this.dialogueManager = new DialogueManager(gameReference, gameReference.Content.Load<SpriteFont>("Fonts/DialogueFont")); // This spawns the character in the right place in the map. foreach (MapObject obj in levelMap.ObjectLayers["Spawn"].MapObjects) { if (obj.Name.Substring(0, 5) == "start" && obj.Name.Substring(5) == oldLevel.Substring(5)) { this.entities["character"].Location = new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y); } if (obj.Name.Contains("Friend")) { this.entities.Add(obj.Name, new OldManFriend(new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y))); this.entities[obj.Name].Load(gameReference.Content); } if (obj.Name.Contains("Enemybutterfly")) { this.entities.Add(obj.Name, new ButterflyEnemy(new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y), gameReference.Content)); this.entities[obj.Name].Load(gameReference.Content); } if (obj.Name.Contains("Enemybooger")) { this.entities.Add(obj.Name, new BoogerShooterEnemy(new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y), gameReference.Content)); this.entities[obj.Name].Load(gameReference.Content); } if (obj.Name.Contains("BunnyTrigger")) { this.entities.Add(obj.Name, new BunnyTrigger(new Rectangle(obj.Bounds.Left, obj.Bounds.Top, obj.Bounds.Width, obj.Bounds.Height), gameReference)); this.entities[obj.Name].Load(gameReference.Content); ((Trigger)this.entities[obj.Name]).ReactivateTime = (int)obj.Properties["ReactivateTime"].AsInt32; } else if (obj.Name.Contains("Trigger")) { this.entities.Add(obj.Name, new Trigger(new Rectangle(obj.Bounds.Left, obj.Bounds.Top, obj.Bounds.Width, obj.Bounds.Height), gameReference)); this.entities[obj.Name].Load(gameReference.Content); ((Trigger)this.entities[obj.Name]).ReactivateTime = (int)obj.Properties["ReactivateTime"].AsInt32; ((Trigger)this.entities[obj.Name]).Type = obj.Properties["Type"].Value; // Don't ask... I'm just registering an event handler... gameReference.EventManager.register("Activate" + obj.Name, new HandleEvent(((Trigger)this.entities[obj.Name]).triggerHandler)); } if (obj.Name == "LvlInfo") { Console.WriteLine("Found Level Information"); try { if (obj.Properties.Keys.Contains("DialogPath")) { DialogueLoader dialogueLoader = gameReference.Content.Load<DialogueLoader>(obj.Properties["DialogPath"].Value); Console.WriteLine("DialogPath Found"); this.dialogueManager.Load(dialogueLoader.Conversations); } } catch (Exception except) { Console.Error.WriteLine("Could not load the dialogue properly: " + except.Message); } try { if (obj.Properties.Keys.Contains("QuestPath")) { QuestMetaLoader METALoader = gameReference.Content.Load<QuestMetaLoader>(obj.Properties["QuestPath"].Value); Console.WriteLine("QuestPath Found"); for (int x = 0; x < METALoader.Quests.Count; x++) { var questIn = from quest in gameReference.QuestManager.quests where quest.QuestTitle.Equals(METALoader.Quests.ElementAt(x).QuestTitle) select quest.QuestTitle; bool found = false; foreach (string name in questIn) { found = true; } if (!found) { // Load the quest creator this.questCreator = new QuestCreator(METALoader, gameReference); } } } } catch (Exception except) { Console.Error.WriteLine("Could not load the quests properly: " + except.Message); } try { if (obj.Properties.Keys.Contains("InitialQuest")) { var questIn = from quest in gameReference.QuestManager.quests where quest.QuestTitle.Equals(obj.Properties["InitialQuest"].Value) select quest.QuestTitle; bool found = false; foreach (string name in questIn) { found = true; } if (!found) { // Load the test quest Dictionary<string, string> payload = new Dictionary<string, string>(); payload.Add("QuestName", obj.Properties["InitialQuest"].Value); Event eventInfo = new Event("ActivateQuest", payload); gameReference.EventManager.notify(eventInfo); } Console.WriteLine("InitialQuest Found"); } } catch (Exception except) { Console.Error.WriteLine("Could not load the initial quest properly: " + except.Message); } } } Camera.Pos = new Vector2(this.entities["character"].DrawingBox.X + entities["character"].DrawingBox.Width / 2, this.entities["character"].DrawingBox.Y + entities["character"].DrawingBox.Height / 2); // This is a fairly ugly way of making the tiles draw in the right locations. screenRect.X = (int)Camera.Pos.X - gameReference.GraphicsDevice.Viewport.Width / 2; if (screenRect.X < 0) screenRect.X = 0; screenRect.Y = (int)Camera.Pos.Y - gameReference.GraphicsDevice.Viewport.Height / 2; if (screenRect.Y < 0) screenRect.Y = 0; screenRect.Width = (int)Camera.Pos.X + gameReference.GraphicsDevice.Viewport.Width / 2; screenRect.Height = (int)Camera.Pos.Y + gameReference.GraphicsDevice.Viewport.Height / 2; gameReference.CutsceneManager.PlayLevelLoad(gameReference); // Load the dialogue manager... if (this.dialogueManager == null) throw new NullReferenceException("Could not load the dialogue manager, or reference to dialogue XML is MISSING.", null); gameReference.audioManager.playBackgroundMusic(levelNum); }
/// <summary> /// Loads the level from a descriptive script file on the harddrive. /// </summary> public void Load(string newLevel, string oldLevel, Pantheon gameReference) { levelMap = gameReference.Content.Load<Map>(newLevel); levelNum = newLevel; this.entities.Add("character", gameReference.player); this.entities["character"].Load(gameReference.Content); // This spawns the character in the right place in the map. foreach (MapObject obj in levelMap.ObjectLayers["Spawn"].MapObjects) { if (obj.Name.Substring(0, 5) == "start" && obj.Name.Substring(5) == oldLevel.Substring(5)) { this.entities["character"].Location = new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y); } if (obj.Name.Contains("Friend")) { this.entities.Add(obj.Name, new OldManFriend(new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y))); this.entities[obj.Name].Load(gameReference.Content); } if (obj.Name.Contains("Enemy")) { this.entities.Add(obj.Name, new ButterflyEnemy(new Vector2(obj.Bounds.Center.X, obj.Bounds.Center.Y), gameReference.Content)); this.entities[obj.Name].Load(gameReference.Content); } } Camera.Pos = new Vector2(this.entities["character"].Location.X, this.entities["character"].Location.Y); gameReference.CutsceneManager.PlayLevelLoad(gameReference); // Load the dialogue manager... this.dialogueManager = new DialogueManager(gameReference.Content, gameReference.Content.Load<SpriteFont>("Fonts/DialogueFont")); }