Implementing items in a game

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

Implementing items in a game

Post by KungFuLu »

Hi,

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
Then in C++ I have a simple Item Class which looks something like this (simplified)

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
};
And to this I add a dynamic vector, which contains all in the world existing items and a dynamic vector for the inventory, which contains the gathered items.

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
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

Post by KungFuLu »

Thanks for sharing this project.
On principle it seems to be pretty similar to my ideaa, but the idea with the ObjectManager is great.
Post Reply