public Level(int columnCount, int rowCount, int tileSize, List <Entity> tiles, LevelContainer levelInformation, GameScene gameScene) { this.columnCount = columnCount; this.rowCount = rowCount; this.tiles = tiles; this.tileSize = tileSize; this.levelInformation = levelInformation; this.gameScene = gameScene; Init(columnCount, rowCount, tileSize); SetupPathFinding(); LoadWeapons(gameScene.LoadedTextures["projectile"]); }
public static bool LoadLevel(string path, int tileSize, out int columnCount, out int rowCount, out List <Entity> tiles, Dictionary <string, Texture2D> loadedTextures, out LevelContainer level) { columnCount = -1; rowCount = -1; tiles = new List <Entity>(); level = default(LevelContainer); if (File.Exists(path)) { object result = null; XmlSerializer xml = new XmlSerializer(typeof(LevelContainer)); using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { result = xml.Deserialize(stream); } if (result != null) { level = (LevelContainer)result; string[] lines = level.MapLayout; rowCount = lines.Length; for (int y = 0; y < rowCount; y++) { columnCount = lines[y].Length; if (y == 0) { Init(columnCount, rowCount, tileSize); } for (int x = 0; x < columnCount; x++) { int value = -1; if (int.TryParse(lines[y][x].ToString(), out value)) { if (loadedTextures.ContainsKey(value.ToString())) { if (value == 0) { tiles.Add(new VisableEntity(loadedTextures[value.ToString()], 1, 0, Vector2.One, Color.White, value.ToString(), new Vector2(x * tileSize, y * tileSize))); } else if (value == 1) { new InteractivObject(true, loadedTextures[value.ToString()], 1, 0, Vector2.One, Color.White, value.ToString(), new Vector2(x * tileSize, y * tileSize)); } else if (value == 2) { new InteractivObject(true, loadedTextures[value.ToString()], 1, 0, Vector2.One, Color.White, "Cover", new Vector2(x * tileSize, y * tileSize)); } else if (value < 6) { //Interactive tiles.Add(new VisableEntity(loadedTextures[value.ToString()], 1, 0, Vector2.One, Color.White, "Entries", new Vector2(x * tileSize, y * tileSize), true, true)); } else if (value == 6) { tiles.Add(new InteractivObject(false, loadedTextures["0"], 1, 0, Vector2.One, Color.White, "RescueZone", new Vector2(x * tileSize, y * tileSize))); /*Projectile projectile = new Projectile() * Player p = new Player(true, Game1.LoadedTextures[value.ToString()], 0, 0, Vector2.One, Color.White, value.ToString(), new Vector2(x * tileSize, y * tileSize)); * p.PickupWeapon(new Weapon("Primary", , Equipment.EquipmentType.Useable, 100, null, 1, false, 1))*/ } else { //Enmeies, Player, Hostage, RescueZone tiles.Add(new VisableEntity(loadedTextures[value.ToString()], 1, 0, Vector2.One, Color.White, value.ToString(), new Vector2(x * tileSize, y * tileSize))); } } else { Console.WriteLine("Couldn't found asset: " + value.ToString()); } } } } } //Load File /* * 0 = Empty field * 1 = Wall * 2 = Obstacale * 3 = Door * 4 = Breakable Window * 5 = Breakable Wall * 6 = RescueZone * 7 = Enemy * 8 = Hostage * 9 = Player */ return(true); } return(false); }
private void CreateLevelFile() { string Name = "level01"; LevelContainer container = new LevelContainer(); container.Name = Name; container.MapLayout = File.ReadAllLines("Content/Levels/BaseFiles/" + Name + ".txt"); TextureAssignment[] ass = new TextureAssignment[7]; ass[0] = new TextureAssignment() { Id = 0, Collidable = false, Path = "Content/Textures/0" }; ass[1] = new TextureAssignment() { Id = 1, Collidable = true, Path = "Content/Textures/1" }; ass[2] = new TextureAssignment() { Id = 2, Collidable = true, Path = "Content/Textures/2" }; ass[3] = new TextureAssignment() { Id = 3, Collidable = true, Path = "Content/Textures/3" }; ass[4] = new TextureAssignment() { Id = 4, Collidable = true, Path = "Content/Textures/4" }; ass[5] = new TextureAssignment() { Id = 5, Collidable = true, Path = "Content/Textures/5" }; ass[6] = new TextureAssignment() { Id = 6, Collidable = false, Path = "Content/Textures/6" }; container.TextureMapping = ass; CharacterInformation[] characters = new CharacterInformation[11]; int id = 0; characters[id++] = CreateCharacter(CharacterType.Enemy, 1, 14, 145, new string[2] { "ak12", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 4, 11, 180, new string[2] { "mp5", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 3, 14, 180, new string[2] { "ak12", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 7, 5, 270, new string[2] { "416-c", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 7, 9, 325, new string[2] { "g36c", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 9, 4, 0, new string[2] { "ak12", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 9, 12, 120, new string[2] { "p90", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 11, 8, 180, new string[2] { "m1014", "p9" }); characters[id++] = CreateCharacter(CharacterType.Enemy, 12, 15, 180, new string[2] { "f2", "p9" }); characters[id++] = CreateCharacter(CharacterType.Player, 17, 10, 270, null); characters[id++] = CreateCharacter(CharacterType.Hostage, 12, 6, 270, null); container.Characters = characters; string path = "Content/Levels/Training/" + Name + ".xml"; if (File.Exists(path)) { File.Delete(path); } XmlSerializer xml = new XmlSerializer(typeof(LevelContainer)); using (FileStream stream = new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite)) { xml.Serialize(stream, container); } }