This topic is now archived and is closed to further replies.

RPG game question

This topic is 5091 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

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?

Share this post

Link to post
Share on other sites
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.


Share this post

Link to post
Share on other sites
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;

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

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

Share this post

Link to post
Share on other sites