public void LoadLevelSelection(string fileAddress,ContentManager content) { levelData.Clear(); BFFileReader reader = new BFFileReader(fileAddress); reader.Open(); string line = null; while((line = reader.ReadLine())!= null) { LevelData levelInfo; string[] param = line.Split(' '); levelInfo.name = param[0]; levelInfo.texture = content.Load<Texture2D>(param[1]); levelData.AddLast(levelInfo); } reader.Close(); data = levelData.First; //load the left and right arrow textures leftArrowTex = content.Load<Texture2D>("Left"); rightArrowTex = content.Load<Texture2D>("Right"); Texture2D exit = content.Load<Texture2D>("Exit"); Texture2D start = content.Load<Texture2D>("Resume"); font = content.Load<SpriteFont>("Font"); selection = new Menu(4, new Rectangle(parent.ScreenWidth/2 -(exit.Width/2),parent.ScreenHeight/2+15,exit.Width,exit.Height),start,exit); time = InputDelay; }
public bool loadRoom(string roomAddress, ContentManager content, Shader shader, GraphicsDevice device,string[] selectCombatants) { //load the menu Texture2D exit = content.Load<Texture2D>("Exit"); Texture2D resume = content.Load<Texture2D>("Resume"); Combatant.PauseMenu = new Menu(4, new Rectangle( parent.ScreenWidth / 2 - (exit.Width / 2), parent.ScreenHeight / 2 - (exit.Height / 2 * 2), exit.Width, exit.Height), resume, exit); hasWon = false; BFFileReader reader = new BFFileReader(roomAddress); reader.Open(); Dictionary<string, RefModel> modelDefs = new Dictionary<string, RefModel>(); string line; //read all of the info in the script #region room parser while ((line = reader.ReadLine()) != null) { string[] param = line.Split(' '); //read the param switch (param[0]) { case "ModelDef": { //add the new modelname to the hashtable BFModel model = new BFModel();//*** model.model = content.Load<Model>(param[1]); shader.setEffects(model); //add the model to the hashtable of models models.Add(param[1], model); break; } case "Music": { //set music music = content.Load<SoundEffect>(param[1]); break; } case "Model": { string modelName = param[1]; RefModel refModel = new RefModel(); while ((line = reader.ReadLine()) != null && line != "}") { //keep reading into this modelRef param = line.Split(' '); switch (param[0]) { case "ModelID": { //set the model id of this ref mode refModel.ModelID = param[1]; break; } case "CollideType": { switch (param[1].ToUpper()) { case "AABB": { refModel.ORIGEN = new AABB(); refModel.CollisionType = Origen.Collision_Type.AABB; break; } case "NONE": { refModel.CollisionType = Origen.Collision_Type.NONE; break; } case "BC": { refModel.ORIGEN = new BC(); refModel.CollisionType = Origen.Collision_Type.BC; break; } case "BS": { refModel.ORIGEN = new BS(); refModel.CollisionType = Origen.Collision_Type.BS; break; } } break; } case "OrigenX": { refModel.X = float.Parse(param[1]); break; } case "OrigenY": { refModel.Y = float.Parse(param[1]); break; } case "OrigenZ": { refModel.Z = float.Parse(param[1]); break; } case "RotX": { refModel.RotX = float.Parse(param[1]); break; } case "RotY": { refModel.RotY = float.Parse(param[1]); break; } case "RotZ": { refModel.RotZ = float.Parse(param[1]); break; } case "HalfWidth": { refModel.HalfWidth = float.Parse(param[1]); break; } case "HalfHeight": { refModel.HalfHeight = float.Parse(param[1]); break; } case "HalfLength": { refModel.HalfLength = float.Parse(param[1]); break; } case "Radius": { refModel.Radius = float.Parse(param[1]); break; } case "TransX": { refModel.TransX = float.Parse(param[1]); break; } case "TransY": { refModel.TransY = float.Parse(param[1]); break; } case "TransZ": { refModel.TransZ = float.Parse(param[1]); break; } } } refModel.updateMatrix(); //add the refmodel to the list of modelsDefs modelDefs.Add(modelName, refModel); break; } case "DrinkSpawner": { string modelID = ""; float X = 0, Y = 0, Z = 0, RotX = 0, RotY = 0, RotZ = 0,spawnTime = 0,drinkStrength = 0, halfWidth = 0,halfLength = 0,halfHeight = 0,transX = 0,transY = 0,transZ = 0; while ((line = reader.ReadLine()) != null && line != "}") { param = line.Split(' '); switch (param[0]) { case "X": { X = float.Parse(param[1]); break; } case "Y": { Y = float.Parse(param[1]); break; } case "Z": { Z = float.Parse(param[1]); break; } case "RotX": { RotX = float.Parse(param[1]); break; } case "RotY": { RotY = float.Parse(param[1]); break; } case "RotZ": { RotZ = float.Parse(param[1]); break; } case "ModelID": { modelID = param[1]; break; } case "SpawnTime": { spawnTime = float.Parse(param[1]); break; } case "DrinkStrength": { drinkStrength = float.Parse(param[1]); break; } case "HalfWidth": { halfWidth = float.Parse(param[1]); break; } case "HalfHeight": { halfHeight= float.Parse(param[1]); break; } case "HalfLength": { halfLength = float.Parse(param[1]); break; } case "TransX": { transX = float.Parse(param[1]); break; } case "TransZ": { transZ = float.Parse(param[1]); break; } case "TransY": { transY = float.Parse(param[1]); break; } } } DrinkSpawner drinkSpawner = new DrinkSpawner(); drinkSpawner.CollisionType = Origen.Collision_Type.AABB; drinkSpawner.ORIGEN = new AABB(); drinkSpawner.X = X; drinkSpawner.Y = Y; drinkSpawner.Z = Z; drinkSpawner.StartX = X; drinkSpawner.StartY = Y; drinkSpawner.StartZ = Z; drinkSpawner.DrinkStrength = drinkStrength; drinkSpawner.HalfHeight = halfHeight; drinkSpawner.HalfLength = halfLength; drinkSpawner.HalfWidth = halfWidth; drinkSpawner.ModelID = modelID; drinkSpawner.RotX = RotX; drinkSpawner.RotY = RotY; drinkSpawner.RotZ = RotZ; drinkSpawner.TransX = transX; drinkSpawner.TransY = transY; drinkSpawner.TransZ = transZ; drinkSpawner.DrinkSpawnTime = spawnTime; drinkSpawner.SpawnTime = spawnTime; drinkSpawner.updateMatrix(); drinks.Add(drinkSpawner); break; } case "ModelGroup": { List<string> includedModels = new List<string>(); float X = 0, Y = 0, Z = 0, RotX = 0, RotY = 0, RotZ = 0; while ((line = reader.ReadLine()) != null && line != "}") { param = line.Split(' '); switch (param[0]) { case "X": { X = float.Parse(param[1]); break; } case "Y": { Y = float.Parse(param[1]); break; } case "Z": { Z = float.Parse(param[1]); break; } case "RotX": { RotX = float.Parse(param[1]); break; } case "RotY": { RotY = float.Parse(param[1]); break; } case "RotZ": { RotZ = float.Parse(param[1]); break; } case "IncludeModel": { includedModels.Add(param[1]); break; } } } //now add the models to the scenes models foreach (string modelName in includedModels) { //load the model to copy the model data from RefModel temp = (RefModel)modelDefs[modelName]; RefModel copy = new RefModel(); copy.ORIGEN = new AABB(); copy.ORIGEN.Type = Origen.Collision_Type.AABB; copy.HalfHeight = temp.HalfHeight; copy.HalfLength = temp.HalfLength; copy.HalfWidth = temp.HalfWidth; copy.X = temp.X + X; copy.Y = temp.Y + Y; copy.Z = temp.Z + Z; copy.RotX = temp.RotX + RotX; copy.RotY = temp.RotY + RotY; copy.RotZ = temp.RotZ + RotZ; copy.TransX = temp.TransX; copy.TransY = temp.TransY; copy.TransZ = temp.TransZ; copy.ModelID = temp.ModelID; copy.updateMatrix(); //add the copy parts.Add(copy); } break; } case "XWidth": { xWidth = float.Parse(param[1]); break; } case "YWidth": { yWidth = float.Parse(param[1]); break; } case "ZWidth": { zWidth = float.Parse(param[1]); break; } case "LeftWallTexture": { leftWallTex = content.Load<Texture2D>(param[1]); break; } case "RightWallTexture": { rightWallTex = content.Load<Texture2D>(param[1]); break; } case "FrontWallTexture": { frontWallTex = content.Load<Texture2D>(param[1]); break; } case "BackWallTexture": { backWallTex = content.Load<Texture2D>(param[1]); break; } case "CeilingTexture": { ceilingTex = content.Load<Texture2D>(param[1]); break; } case "FloorTexture": { floorTex = content.Load<Texture2D>(param[1]); break; } case "Light": { switch (param[1]) { case "X": { lightPos.X = float.Parse(param[2]); break; } case "Y": { lightPos.Y = float.Parse(param[2]); break; } case "Z": { lightPos.Z = float.Parse(param[2]); break; } case "Power": { lightPower = float.Parse(param[2]); break; } case "Ambient": { ambientPower = float.Parse(param[2]); break; } } break; } case "FloorXDensity": { floorXDensity = float.Parse(param[1]); break; } case "FloorYDensity": { floorYDensity = float.Parse(param[1]); break; } case "WallXDensity": { wallXDensity = float.Parse(param[1]); break; } case "WallYDensity": { wallYDensity = float.Parse(param[1]); break; } case "BarX": { barX = float.Parse(param[1]); break; } case "BarY": { barY = float.Parse(param[1]); break; } case "BarWidth": { barWidth = float.Parse(param[1]); break; } } } #endregion //close the file reader.Close(); //play the music if the music exists if (music != null) { instance = music.CreateInstance(); instance.IsLooped = true; instance.Play(); } winSong = content.Load<SoundEffect>("WinSong").CreateInstance(); winSong.IsLooped = true; //set up the bounding box for the room //init the buffers initBuffers(device); bounds = new AABB(0, 0, 0, xWidth, yWidth, zWidth); //load the combatants after clearing the list of the old ones combatants.Clear(); loadCombatants(content,selectCombatants,parent.NumOfPlayers); return true; }
public void loadCombatant(ContentManager content,string combatDef,PlayerIndex player) { this.player = player; BFFileReader reader = new BFFileReader(combatDef); List<Texture2D> textures = new List<Texture2D>(); reader.Open(); string line = ""; #region Combatant parser while ((line = reader.ReadLine()) != null) { string[] param = line.Split(' '); switch(param[0]) { case "ModelID": { ModelID = param[1]; break; } case "HalfWidth": { HalfWidth = float.Parse(param[1]); break; } case "HalfHeight": { HalfHeight = float.Parse(param[1]); break; } case "HalfLength": { HalfLength = float.Parse(param[1]); break; } case "Radius": { Radius = float.Parse(param[1]); break; } case "TransX": { TransX = float.Parse(param[1]); break; } case "TransY": { TransY = float.Parse(param[1]); break; } case "TransZ": { TransZ = float.Parse(param[1]); break; } case "Texture": { textures.Add(content.Load<Texture2D>(param[1])); break; } case "CollideType": { switch (param[1].ToUpper()) { case "AABB": { ORIGEN = new AABB(); CollisionType = Origen.Collision_Type.AABB; break; } case "NONE": { CollisionType = Origen.Collision_Type.NONE; break; } case "BC": { ORIGEN = new BC(); CollisionType = Origen.Collision_Type.BC; break; } case "BS": { ORIGEN = new BS(); CollisionType = Origen.Collision_Type.BS; break; } } break; } } } #endregion reader.Close(); model = new AnimatedModel(ModelID); model.LoadContent(content); //load the textures for the model model.textures = textures.ToArray(); //play an animation model.PlayAnimation("TakePunchLeft", false); RotX -= (float)Math.PI/2; }
public void loadCombatants(string address,ContentManager content) { BFFileReader reader = new BFFileReader(address); reader.Open(); string line; while((line = reader.ReadLine()) != null) { string dataName = ""; string[] param1 = line.Split(' '); List<Texture2D> textures = new List<Texture2D>(); BFFileReader reader2 = new BFFileReader("Files/Combatants/" + param1[1] + ".txt"); reader2.Open(); string line2; while ((line2 = reader2.ReadLine()) != null) { string[] param = line2.Split(' '); if(param[0] == "Texture") { textures.Add(content.Load<Texture2D>(param[1])); } else if(param[0] == "ModelID") { dataName = param[1]; } } CharacterInfo info = new CharacterInfo(); AnimatedModel model = new AnimatedModel(dataName); string name = param1[0]; string modelName = param1[1]; info.model = model; info.model.LoadContent(content); info.name = name; info.modelName = modelName; info.model.textures = textures.ToArray(); combatants.AddLast(info); reader2.Close(); numOfPlayers = parent.NumOfPlayers; } font = content.Load<SpriteFont>("Font"); //play all of the animations on the models foreach(CharacterInfo info in combatants) { info.model.PlayAnimation("WalkFight", true); } data = combatants.First; reader.Close(); wallTexture = content.Load<Texture2D>("walls"); Texture2D start, cancel; start = content.Load<Texture2D>("Start"); cancel = content.Load<Texture2D>("Exit"); menu = new Menu(4, new Rectangle(parent.ScreenWidth / 2 - (start.Width / 2), parent.ScreenHeight / 2, start.Width, start.Height), start, cancel); }