64x64 Array question

Non-platform specific questions.

64x64 Array question

Postby phyzix5761 » Sun Apr 15, 2012 12:18 am

I am trying to create a 64x64 tile map maker with certain rules per tile. Anyone have any ideas how I can go about this? I thought using a 2d array could help but I'm not sure.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: 64x64 Array question

Postby skydereign » Sun Apr 15, 2012 1:05 am

What do you mean by certain rules? Can they be represented by integer values? If so you can use a 3d array.
Code: Select all
int array[64][64][3]; // 3 rules per tile

#define TYPE 0
#define COLOR 1
#define OTHER 2

// an example function using the array
void
set_tile (int x, int y, int type, int color, int other)
{
    array[x][y][TYPE] = type;
    array[x][y][COLOR] = color;
    array[x][y][OTHER] = other;
}

If you need something more complex, you might try using a 2d array of structs.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: 64x64 Array question

Postby phyzix5761 » Sun Apr 15, 2012 1:55 am

The rules are something like: If this type of tile is above this other then a new one of a specific type needs to be created. So for example if tile [1][1] is equal to 1 then tile [2][1] can only be equal to 2,3, or 5. Can I use this type of array like this?
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: 64x64 Array question

Postby skydereign » Sun Apr 15, 2012 3:04 am

Okay, so you mean actual rules to which tiles can be placed where. In that case you just need to put code in the placing tile section. I'm not entirely sure how you plan to do tile input, but just say on the mouse button down, you can check if the tile to the left is a certain type, and/or if the tile above is, etc. Since tiles are only stored as a single value, you only need a 2d array, and the actual rules will be defined in the place tile event.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron