RPG game question

Started by
3 comments, last by ssibal 20 years, 3 months ago
I am wondering how to handle the map/objects in a RPG? I have a 2d array with all the tiles for drawing the map, thats good, but how do i handle objects on tiles? Would I have to create another array that says what objects are on what tiles? And what if i want more than one object per tile? Then would I have to create a third array for path finding? It seems wasteful to have so many arrays. Is there a more efficient way of handling this?
Advertisement
I would have one array of a tile class. The tile class would conatin a pointer to the tile image and details, as well as a linked list of objects.
You could also run a check through the objects, and mathematically calcuate which tile they are on. Quite easy maths wise, you could simply divide the amount of tiles, by the size of the land and you can find the cordinates of each tile. Then check to see which tile the object is in.

RPGamer
Eternal Destiny - A 3D RPGHelp Wanted! Email us! join@eternaldestinyonline.com
So would this mean one array that would hold the information for every object as well as the graphics for every object in the world?
This is how I would do it, but it might not be the easiest way if you dont already know what your doing.

have an array of objects that represent items in the game

struct sObject
{
char name[30];
int type;
etc...
};

sObject ObjectArray[numobjects];

then have an a simple liked list class
class cObjectNode
{
cObjectNode m_pNextNode; //next node in liked list
int ObjectIndex; //index number in object list this node points to
//add functions for adding another node, and getting index number
BOOL AddNode(int objectnum);
int GetObjectNumber();
}

Now you have an array of tiles for your map spaces
struct sTile
{
SpriteClass sprite; //sprite for drawing ground at this location
cObjectNode *ObjectNode; //pointer to a liked list of nodes that point to the objects index number in the objec table, or null of no objects are present
}

sTile Map[NumTilesOnMap];

Now what makes this easy, is...
in your loop, when your going through your map array drawing the ground tiles, you check to see if Map[n].ObjectNode if not NULL. If its not, you travel through the liked list that Map[n].ObjectNode points to. When you read each node, you draw the object that Map[n].ObjectNode->ObjectIndex points to.
If you object array has a function for drawint the object, say its called Draw, then you would do this
ObjectArray[Map[n].ObjectNode->GetObjectNumber()].Draw();

I wish I was more articulate at explaining what I am trying to explain, but oh well. Perhaps this helps. Read it after a few nights without sleep, and it just might make perfect sense



class cMapTile
{

This topic is closed to new replies.

Advertisement