• Advertisement

Archived

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

Sorry for the newbie question, but I just wanted to know...

This topic is 6524 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 have a demo that loads my tileset of 32X32 tiles. The data array supports only 10 tiles (0-9), and I was wondering how I could load a full tileset of 100 or more tiles. The array goes something like this: char *world[21] = { "111111111111111111111111111111", "100000000000000000000000000001", "100002222220000000000000077701", "100002222223333333333000077701", "100002222227777777773000070001", "100002222227777777773000070001", "100000000377777777773000070001", "107777700377777777773000070001", "177777770377777777773000770001", "107777700377777777773007700001", "100777770377777777773777000001", "100000707377777777773000000001", "100007777377777777773000000001", "100000000302222777773000000001", "100000000332222777773000000001", "100000000002222333333000000001", "100000666666666666666666600001", "100000800000000000000000800001", "100000800000000000000000800001", "100000000000000000000000000001", "111111111111111111111111111111", }; (This is a data structure from a different source file, but my code is exactly the same, just bigger.) Would I just create a 2 dimensional array and fill in the index numbers? something like: char *world [30][21] = { {0,21,22,0,...}, {24,9,37,0,...}, . . . }; and so on? or am I doing this totally wrong? or should I not be asking this? :o)

Share this post


Link to post
Share on other sites
Advertisement
Instead of using an array of strings, try using a double array of chars, but use their value instead. For instance:

char world[5][5] =
{
{1,1,1,1,1},
{1,0,0,0,1},
{20,0,100,0,90},
{1,0,0,0,1},
{1,1,1,1,1}
};

Then you can have your tiles in another array:
Tile allTiles[256];
And access tile (4, 3) using:
allTiles[world[3][4]];

As a final note, the best way to create tiled maps is to load the data from files, but I can see using predefined arrays to learn with.

Hope all this helps!


Wraith
BasketQase Software

Share this post


Link to post
Share on other sites
I made a 2d Game along time ago and what I did was I just used every Character, and each character represents a tile.

"lw429Sfka"
"sfd3443Kl"
"gs34FD34d"
"s5325FDsd"
Just like that then
switch(curr_cell)
{
case ''l'':
DrawCell(cell[0]);
}

Something like that

Share this post


Link to post
Share on other sites
Hrm... I kinda understand, but not fully. I haven''t really done enough to implement my own little tricks (or anyone else''s). In the book here, it says you can also do a struct
like:

typedef struct TILED_IMAGE_TYP
{
TILE image[7][10]
} TILED_IMAGE, *TILE_IMAGE_PTR;

// and then do:

TILED_IMAGE world[3][3] =
{
.
.
.
}

Would this work as well?

Share this post


Link to post
Share on other sites

  • Advertisement