Jump to content
  • Advertisement
Sign in to follow this  
Glenn987

How to best keep track of all the game items

This topic is 2647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I am making a game that is 2d and tile based with a client and server and I'm not entirely sure how I should keep track of all of the different items I have.

Basically every item (or pretty much every "thing") will have an associated sprite and properties.
For example a grass tile will have an image of grass and the property that you can walk on it. A shield will have an image of a shield and whatever the defense stats are.

Here's my plan so far:
I will have an xml file for each thing.
Each xml will be an item or tile or whatever and all of the properties of that item are contained within it. The xml would also reference the correct image of the item.
Then I was going create an application that would load all of the xml's and images and create a binary file of all of this information to be loaded by the client.
This application could possibly be extended to use as an item editor (rather than manually changing xml files).

This way I have a single binary file containing all the information about every item. (Would eventually be used by a map editor I plan on creating as well)

I would also have the application generate a separate binary file for the server to load (possibly with more/different information? in the very least images would be omitted).

Also I have no idea what the folder structure for storing all of this should be or how I should name the xmls/images.
For example should I could have like:
items
trees
1.xml
1.png
tiles
grass1.xml
grass1.png
shields
supercoolshield.xml
supercoolshield.png

or possibly just an item folder with everything in it (although I anticipate hundreds of images)


That is my current plan and I'd like to know if you guys have any suggestions or see any issues with this approach. Thanks =)

Share this post


Link to post
Share on other sites
Advertisement
Ok, first of all, we should define "ITEMS" because grass and trees are not items but rather world objects / terrain / tiles.

You should seperate ITEMS like sword, armor, potion etc. because those will have other options that tiles.

For the terrain like grass, mud, water, bushes etc. I would make a 2D array of TILE structure

struct TILE
{
int textureID;
int attribute;
};


Where textureID = id of the texture and attribute = what kind of tile that is (can you walk over it / does it hurt you / heal you etc.)
The best options is, to make somekind of grid for the texture which is created from different tiles instead holding a single image file
for each tile. That way you can easily attach "Tileset" to the map and draw the tile with it's ID which is the id of the tile sequence in that
tileset (example: you have texture big 512x512 - you can divide that texture to 16x16 tiles of size 32x32 pixel). First tile in the grid would
have an ID of 0, second one 1, then 2, 3 ,4 ,5 ,..... 256.

So, all you save is the ID of the image in the tileset and maybe the number of the tileset if you have more.

For the items, you'll have to make another structure then. There are many steps toward this like having only itemID which is connected to the
item in some database and you get additional info of it from there then.
struct ITEM
{
int itemID;
int textureID;
}


itemID = id that tells you which item to read info from // textureID = id of the texture again. However, this is just raw explenation how to save data
in your file. You'll have to extend everything later in the game.

Share this post


Link to post
Share on other sites

Ok, first of all, we should define "ITEMS" because grass and trees are not items but rather world objects / terrain / tiles.

You should seperate ITEMS like sword, armor, potion etc. because those will have other options that tiles.

For the terrain like grass, mud, water, bushes etc. I would make a 2D array of TILE structure

struct TILE
{
int textureID;
int attribute;
};


Where textureID = id of the texture and attribute = what kind of tile that is (can you walk over it / does it hurt you / heal you etc.)
The best options is, to make somekind of grid for the texture which is created from different tiles instead holding a single image file
for each tile. That way you can easily attach "Tileset" to the map and draw the tile with it's ID which is the id of the tile sequence in that
tileset (example: you have texture big 512x512 - you can divide that texture to 16x16 tiles of size 32x32 pixel). First tile in the grid would
have an ID of 0, second one 1, then 2, 3 ,4 ,5 ,..... 256.

So, all you save is the ID of the image in the tileset and maybe the number of the tileset if you have more.

For the items, you'll have to make another structure then. There are many steps toward this like having only itemID which is connected to the
item in some database and you get additional info of it from there then.
struct ITEM
{
int itemID;
int textureID;
}


itemID = id that tells you which item to read info from // textureID = id of the texture again. However, this is just raw explenation how to save data
in your file. You'll have to extend everything later in the game.


Remember to use an enum for the ID not an integer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!