I'm creating a simple RPG game and currently I am working on weapon objects. I currently have a W_Sword.cs class that has all the properties for any sword type weapons I want to create. For my inventory system I am simply going to have an array that stores integers and each number will represent the ID of an item.
My question is, if I have multiple classes for all types of items (consumables, swords, axes, shields etc.) how should I store all this in like a database for easy access? So if I want to draw a specific weapon I can just call it from a database and create it as an object (on-screen, in the inventory etc.) I'm thinking an XML might be the way to go, but I'm not sure how to get the data from an XML file into my XNA code to create objects etc. from specific items in the XML.
Please let me know if I should elaborate further.
XML is a good way to do this. It will allow for the easy addition of new items by yourself or even the end user.
Are the classes derived from a base class? My thinking is that, if you have a base class Item that consumables, swords, axes, shields, etc inherit from, you could try something like this:
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="Generic.List<MyDataTypes.Item>">
<Item>
<Name>Wooden Sword</Name>
<Properties>10 10 10 10</Properties>
<TextureName>WoodenSword</TextureName>
</Item>
<Item>
<Name>Wooden Shield</Name>
<Properties>10 10 10 10</Properties>
<TextureName>WoodenShield</TextureName>
</Item>
</Asset>
</XnaContent>
Then in your code:
// Load items into content
//http://msdn.microsoft.com/en-us/library/ff604980.aspx
List<Item> listOfItems = Content.Load<List<Item>>("xmlFileName");
foreach (Item item in listOfItems)
{
myItemTexture = Content.Load<Texture2D>(item.TextureName);
...
}
This is a general overview. I'm not currently at a computer with Visual Studio so I doubt the above is syntactically correct. If you wish for further help I can assist later today.