Example #1
0
 public void RechargeWeapon(Recharger recharger)
 {
     Weapon weapon = primaryWeapons.SingleOrDefault(w => w.Name == recharger.Type) ?? secondaryWeapons.SingleOrDefault(w => w.Name == recharger.Type);
     weapon.Power += recharger.Power;
 }
        public void PlaceFurniture()
        {
            furnitures.Clear();

            XDocument doc = XDocument.Load("../../../Furniture.xml");

            foreach (var f in doc.Elements("items").Elements("furnitures").Elements("floor").Where(f => f.Attribute("level").Value == floor.ToString()).Elements())
            {
                FloorTile furn = new FloorTile();
                furn.Rect = new Rectangle(int.Parse(f.Attribute("x").Value) * 20, int.Parse(f.Attribute("y").Value) * 20,
                    int.Parse(f.Attribute("width").Value) * 20, int.Parse(f.Attribute("height").Value) * 20);
                furn.Texture = useForLoadingContent.Content.Load<Texture2D>("MapItems/" + f.Attribute("name").Value);

                furnitures.Add(furn);

                if (f.Attribute("canpassthrough") == null || !bool.Parse(f.Attribute("canpassthrough").Value))
                    for (int i = int.Parse(f.Attribute("x").Value); i < int.Parse(f.Attribute("x").Value) + int.Parse(f.Attribute("width").Value); i++)
                        for (int j = int.Parse(f.Attribute("y").Value); j < int.Parse(f.Attribute("y").Value) + int.Parse(f.Attribute("height").Value); j++)
                            foregroundContourWFurniture[i, j] = Color.Black;
            }

            stairs.Clear();

            foreach (var f in doc.Elements("items").Elements("stairs").Elements())
            {
                if (int.Parse(f.Attribute("floor").Value) == floor)
                {
                    Staircase staircase = new Staircase();
                    staircase.BoundingBox = new Rectangle(int.Parse(f.Attribute("x").Value) * 20, int.Parse(f.Attribute("y").Value) * 20,
                        int.Parse(f.Attribute("width").Value) * 20, int.Parse(f.Attribute("height").Value) * 20);
                    staircase.Texture = useForLoadingContent.Content.Load<Texture2D>("MapItems/" + f.Attribute("name").Value);
                    staircase.Floor = int.Parse(f.Attribute("floor").Value);
                    staircase.ToFloor = int.Parse(f.Attribute("toFloor").Value);
                    stairs.Add(staircase);
                }
            }

            roomDescriptions.Clear();

            foreach (var f in doc.Elements("items").Elements("roomdescriptions").Elements())
            {
                if (int.Parse(f.Attribute("floor").Value) == floor)
                {
                    RoomDescription roomDescription = new RoomDescription();
                    roomDescription.BoundingBox = new Rectangle(int.Parse(f.Attribute("x").Value) * 20, int.Parse(f.Attribute("y").Value) * 20,
                        int.Parse(f.Attribute("width").Value) * 20, int.Parse(f.Attribute("height").Value) * 20);
                    roomDescription.Description = f.Attribute("description").Value;
                    roomDescriptions.Add(roomDescription);
                }
            }

            foreach (var f in doc.Elements("items").Elements("floortiles").Elements())
                tilesMap[new Color(int.Parse(f.Attribute("r").Value), int.Parse(f.Attribute("g").Value), int.Parse(f.Attribute("b").Value))] = useForLoadingContent.Content.Load<Texture2D>("tiles/" + f.Attribute("name").Value);

            weapons.Clear();

            foreach (var f in doc.Elements("items").Elements("placedweapons").Elements("floor").Where(f => f.Attribute("level").Value == floor.ToString()).Elements())
            {
                Weapon weaponDefinition = useForLoadingContent.weaponDefinitions.SingleOrDefault(w => w.Name == f.Attribute("name").Value);
                Weapon weapon = weaponDefinition.Clone();

                weapon.Position = new Vector2(int.Parse(f.Attribute("x").Value), int.Parse(f.Attribute("y").Value));
                weapons.Add(weapon);
            }

            foreach (var f in doc.Elements("items").Elements("placedweapons").Elements(thisPlayer.PlayerType.ToString()).Elements())
            {
                Weapon weaponDefinition = useForLoadingContent.weaponDefinitions.SingleOrDefault(w => w.Name == f.Attribute("name").Value);
                Weapon weapon = weaponDefinition.Clone();
                thisPlayer.AddWeapon(weapon);
            }
            thisPlayer.Score = 0;

            Npcs.Clear();
            foreach (var f in doc.Elements("items").Elements("npcs").Elements("floor").Where(f => f.Attribute("level").Value == floor.ToString()).Elements())
            {
                Npc npc = new Npc(
                new AnimatedTexture(useForLoadingContent.Content.Load<Texture2D>("PlayerSprites/zombiespritesheet"), 4,2,true,8, spriteBatch, 50,50,new Vector2(25,25), null),
                new AnimatedTexture(useForLoadingContent.Content.Load<Texture2D>("PlayerSprites/zombiedeath"), 4, 2, false, 16, spriteBatch, 50, 50, new Vector2(25, 25), null),
                players, thisPlayer, new Vector2(int.Parse(f.Attribute("x").Value), int.Parse(f.Attribute("y").Value)), 50, 10, 10);

                Npcs.Add(npc);
            }

            Rechargers.Clear();
            foreach (var f in doc.Elements("items").Elements("rechargers").Elements("floor").Where(f => f.Attribute("level").Value == floor.ToString()).Elements())
            {
                Recharger recharger = new Recharger
                {
                    Power = int.Parse(f.Attribute("power").Value),
                    Type = f.Attribute("type").Value,
                    Position = new Vector2(int.Parse(f.Attribute("x").Value), int.Parse(f.Attribute("y").Value)),
                    Texture = useForLoadingContent.Content.Load<Texture2D>("MapItems/" + f.Attribute("type").Value + "ammo")
                };

                Rechargers.Add(recharger);
            }

            Doors.Clear();
            foreach (var f in doc.Elements("items").Elements("doors").Elements("floor").Where(f => f.Attribute("level").Value == floor.ToString()).Elements())
            {
                Door door = new Door
                {
                    IsOpen = bool.Parse(f.Attribute("isopen").Value),
                    Position = new Vector2(int.Parse(f.Attribute("x").Value), int.Parse(f.Attribute("y").Value)),
                    Texture = useForLoadingContent.Content.Load<Texture2D>("MapItems/door")
                };

                Doors.Add(door);
            }

            UpdateForegroundContour(0, 0);
        }