64x64 Array question
Posted:
Sun Apr 15, 2012 12:18 am
by phyzix5761
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.
Re: 64x64 Array question
Posted:
Sun Apr 15, 2012 1:05 am
by skydereign
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.
Re: 64x64 Array question
Posted:
Sun Apr 15, 2012 1:55 am
by phyzix5761
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?
Re: 64x64 Array question
Posted:
Sun Apr 15, 2012 3:04 am
by skydereign
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.