I'm currently programming a very small rpg/j 'n' r mix and wonder if there's a better way to manage items. At the moment I have a lua file in which all the data and specific functions for an item type is saved in an array, which looks something like this:
Code: Select all
items = {}
items[0] = {}
items[0].name = "Sword"
items[0].weight = 1500
items[0].objectFile = "sword.x"
items[0].textureFile = "sword.png"
items[0].Action = function()
--Here is what happens if the item is equiped and if you press the left mousebutton (this function is called from inside c++)
end
Code: Select all
class Item
{
private:
int itemNumber; //indicates which item it is (=index of the items array in lua, so itemNumber == 0 would mean it is a sword)
irr::scene::IMeshSceneNode* node; //the scene node for the item
//and so on
public:
Item( int pItemNumber );
void Pick(); //Adds the item to the inventory
// and so on
};
It works fine so far, but somehow I got the feeling that there is an easier way to implement items in my game, so I'd like to hear how someone else did this or if anybody has an idea for a better implementation.
Thanks for reading and I hope it is understandable what I wrote
-Lu