private CharacterInformation CreateCharacter(CharacterType type, int rowIndex, int columnIndex, int rotation, string[] weaponNames, int health = 100) { CharacterInformation character = new CharacterInformation(); switch (type) { case CharacterType.Enemy: character.Name = "Enemy"; character.TeamId = 2; break; case CharacterType.Player: character.Name = "Player"; character.TeamId = 1; break; case CharacterType.Hostage: character.Name = "Hostage"; character.TeamId = 1; break; default: character.Name = "Unknown"; character.TeamId = -1; break; } character.Speed = 0.5f; character.RotationSpeed = 0.5f; character.RowIndex = rowIndex; character.ColumnIndex = columnIndex; character.Type = type; character.Rotation = rotation; character.Health = health; character.WeaponNames = weaponNames; return(character); }
public void Spawn() { //Load Npcs foreach (CharacterInformation item in levelInformation.Characters) { if (item.Type == CharacterType.Enemy) { NPC npc = new NPC(item.Speed, item.RotationSpeed, true, gameScene.LoadedTextures["npc"], 0, item.Rotation, Vector2.One, Color.White, item.Name, new Vector2(item.ColumnIndex * tileSize, item.RowIndex * tileSize), true, true, item.TeamId); npc.AddComponent(new DamageAbleObject(npc, "health", item.Health, item.Health)); for (int i = 0; i < item.WeaponNames.Length; i++) { npc.PickupWeapon(GetWeapon(weapons, item.WeaponNames[i])); } } else if (item.Type == CharacterType.Hostage) { Character character = new Character(item.Speed, item.RotationSpeed, true, gameScene.LoadedTextures["hostage"], 0, item.Rotation, Vector2.One, Color.White, item.Name, new Vector2(item.ColumnIndex * tileSize, item.RowIndex * tileSize), true, true, item.TeamId); } else if (item.Type == CharacterType.Player) { playerInfo = item; } } }
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); } }