private void LoadWorld()
        {
            RpgLibrary.WorldClasses.LevelData levelData =
                Game.Content.Load <RpgLibrary.WorldClasses.LevelData>(@"Game\Levels\Starting Level");

            RpgLibrary.WorldClasses.MapData mapData =
                Game.Content.Load <RpgLibrary.WorldClasses.MapData>(@"Game\Levels\Maps\" + levelData.MapName);


            string[] fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Armor"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Armor/" + Path.GetFileNameWithoutExtension(a);

                ArmorData armorData = Game.Content.Load <ArmorData>(path);
                ItemManager.AddArmor(new Armor(armorData));
            }

            fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Shield"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Shield/" + Path.GetFileNameWithoutExtension(a);

                ShieldData shieldData = Game.Content.Load <ShieldData>(path);
                ItemManager.AddShield(new Shield(shieldData));
            }

            fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Weapon"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Weapon/" + Path.GetFileNameWithoutExtension(a);

                WeaponData weaponData = Game.Content.Load <WeaponData>(path);
                ItemManager.AddWeapon(new Weapon(weaponData));
            }

            CharacterLayerData charData =
                Game.Content.Load <CharacterLayerData>(@"Game\Levels\Chars\Starting Level");
            CharacterLayer characterLayer = new CharacterLayer();

            TileMap map = TileMap.FromMapData(mapData, Game.Content);

            foreach (var c in charData.Characters)
            {
                Character character;

                if (c.Value is NonPlayerCharacterData)
                {
                    Entity entity = new Entity(c.Value.Name, c.Value.EntityData, c.Value.Gender, EntityType.NPC);

                    using (Stream stream = new FileStream(c.Value.TextureName, FileMode.Open, FileAccess.Read))
                    {
                        Texture2D      texture = Texture2D.FromStream(GraphicsDevice, stream);
                        AnimatedSprite sprite  = new AnimatedSprite(texture, AnimationManager.Instance.Animations)
                        {
                            Position = new Vector2(c.Key.X * Engine.TileWidth, c.Key.Y * Engine.TileHeight)
                        };

                        character = new NonPlayerCharacter(entity, sprite);

                        ((NonPlayerCharacter)character).SetConversation(
                            ((NonPlayerCharacterData)c.Value).CurrentConversation);
                    }

                    characterLayer.Characters.Add(c.Key, character);
                }
            }

            map.AddLayer(characterLayer);

            Level level = new Level(map);

            ChestData chestData = Game.Content.Load <ChestData>(@"Game\Chests\Plain Chest");

            Chest chest = new Chest(chestData);

            BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point(10, 10));

            ItemSprite itemSprite = new ItemSprite(
                chest,
                chestSprite);

            level.Chests.Add(itemSprite);

            World world = new World(GameRef, GameRef.ScreenRectangle);

            world.Levels.Add(level);
            world.CurrentLevel = 0;

            AnimatedSprite s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations);

            s.Position = new Vector2(0 * Engine.TileWidth, 5 * Engine.TileHeight);

            EntityData ed = new EntityData("Eliza", 1, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16",
                                           "0|0|0");

            Entity e = new Entity("Eliza", ed, EntityGender.Female, EntityType.NPC);

            NonPlayerCharacter npc = new NonPlayerCharacter(e, s);

            npc.SetConversation("eliza1");
            //world.Levels[world.CurrentLevel].Characters.Add(npc);

            s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations);
            s.Position = new Vector2(10 * Engine.TileWidth, 0);

            ed = new EntityData("Barbra", 2, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16", "0|0|0");

            e = new Entity("Barbra", ed, EntityGender.Female, EntityType.Merchant);

            Merchant  m     = new Merchant(e, s);
            Texture2D items = Game.Content.Load <Texture2D>("ObjectSprites/roguelikeitems");

            m.Backpack.AddItem(new GameItem(ItemManager.GetWeapon("Long Sword"), items, new Rectangle(0, 0, 16, 16)));
            m.Backpack.AddItem(new GameItem(ItemManager.GetWeapon("Short Sword"), items, new Rectangle(16, 0, 16, 16)));

            world.Levels[world.CurrentLevel].Characters.Add(m);
            ((CharacterLayer)world.Levels[world.CurrentLevel].Map.Layers.Find(x => x is CharacterLayer)).Characters.Add(new Point(10, 0), m);
            GamePlayScreen.World = world;

            CreateConversation();

            // ((NonPlayerCharacter)world.Levels[world.CurrentLevel].Characters[0]).SetConversation("eliza1");
        }
Esempio n. 2
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            DataManager.ReadEntityData(Content);
            DataManager.ReadArmorData(Content);
            DataManager.ReadShieldData(Content);
            DataManager.ReadWeaponData(Content);
            DataManager.ReadChestData(Content);
            DataManager.ReadKeyData(Content);
            DataManager.ReadSkillData(Content);

            FontManager.AddFont("testfont", Content.Load <SpriteFont>("Fonts/scenefont"));
            TextureManager.AddTexture("FullSheet", Content.Load <Texture2D>("GUI/ProjectUtumno_full"));
            string[] fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Armor"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Armor/" + Path.GetFileNameWithoutExtension(a);

                ArmorData armorData = Content.Load <ArmorData>(path);
                ItemManager.AddArmor(new Armor(armorData));
            }

            fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Shield"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Shield/" + Path.GetFileNameWithoutExtension(a);

                ShieldData shieldData = Content.Load <ShieldData>(path);
                ItemManager.AddShield(new Shield(shieldData));
            }

            fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Weapon"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Weapon/" + Path.GetFileNameWithoutExtension(a);

                WeaponData weaponData = Content.Load <WeaponData>(path);
                ItemManager.AddWeapon(new Weapon(weaponData));
            }

            PotionData potionData = new PotionData
            {
                Name             = "Minor Healing Potion",
                Type             = "Potion",
                Target           = "Health",
                Price            = 100,
                Weight           = .25f,
                Minimum          = 6,
                Maximum          = 13,
                AllowableClasses = new[] { "Fighter", "Wizard", "Rogue", "Priest" }
            };

            Potion potion = new Potion(potionData);

            ItemManager.AddPotion(potion);

            potionData = new PotionData
            {
                Name             = "Minor Mana Potion",
                Type             = "Potion",
                Target           = "Mana",
                Price            = 100,
                Weight           = .25f,
                Minimum          = 6,
                Maximum          = 13,
                AllowableClasses = new[] { "Wizard", "Priest" }
            };

            potion = new Potion(potionData);

            ItemManager.AddPotion(potion);

            potionData = new PotionData
            {
                Name             = "Minor Stamina Potion",
                Type             = "Potion",
                Target           = "Stamina",
                Price            = 100,
                Weight           = .25f,
                Minimum          = 6,
                Maximum          = 13,
                AllowableClasses = new[] { "Fighter", "Rogue" }
            };

            potion = new Potion(potionData);

            ItemManager.AddPotion(potion);

            GameItemManager.AddItem("Long Sword", new GameItem(ItemManager.GetWeapon("Long Sword"), "FullSheet", new Rectangle(1696, 1408, 32, 32)));
            GameItemManager.AddItem("Short Sword", new GameItem(ItemManager.GetWeapon("Short Sword"), "FullSheet", new Rectangle(800, 1504, 32, 32)));
            GameItemManager.AddItem("Apprentice Staff", new GameItem(ItemManager.GetWeapon("Apprentice Staff"), "FullSheet", new Rectangle(224, 1408, 32, 32)));
            GameItemManager.AddItem("Acolyte Staff", new GameItem(ItemManager.GetWeapon("Acolyte Staff"), "FullSheet", new Rectangle(256, 1408, 32, 32)));
            GameItemManager.AddItem("Leather Armor", new GameItem(ItemManager.GetArmor("Leather Armor"), "FullSheet", new Rectangle(1248, 1216, 32, 32)));
            GameItemManager.AddItem("Chain Mail", new GameItem(ItemManager.GetArmor("Chain Mail"), "FullSheet", new Rectangle(1472, 1184, 32, 32)));
            GameItemManager.AddItem("Studded Leather Armor", new GameItem(ItemManager.GetArmor("Studded Leather Armor"), "FullSheet", new Rectangle(1984, 1120, 32, 32)));
            GameItemManager.AddItem("Light Robes", new GameItem(ItemManager.GetArmor("Light Robes"), "FullSheet", new Rectangle(992, 1216, 32, 32)));
            GameItemManager.AddItem("Medium Robes", new GameItem(ItemManager.GetArmor("Medium Robes"), "FullSheet", new Rectangle(1024, 1216, 32, 32)));
            GameItemManager.AddItem("Minor Healing Potion", new GameItem(ItemManager.GetPotion("Minor Healing Potion"), "FullSheet", new Rectangle(832, 1344, 32, 32)));
            GameItemManager.AddItem("Minor Mana Potion", new GameItem(ItemManager.GetPotion("Minor Mana Potion"), "FullSheet", new Rectangle(576, 1344, 32, 32)));
            GameItemManager.AddItem("Minor Stamina Potion", new GameItem(ItemManager.GetPotion("Minor Stamina Potion"), "FullSheet", new Rectangle(704, 1344, 32, 32)));
        }