Chaos Project

Featured Projects => Advanced RPG Creator => ARC Welder => Topic started by: Apidcloud on December 02, 2012, 10:56:50 am

Title: Autotiles Question
Post by: Apidcloud on December 02, 2012, 10:56:50 am
I don't know whether I should be asking this here, but feel free to move the topic.
I want to ask how you did the autotiles part(pick a specific rect from the autotile based on its location and some other autotiles that might be around)

Did you do it with if's or with some formula? I remember of doing it with if's( :facepalm: took like 3 days to make all the combinations), comparing each tile with 8 bits(where 1 would mean that there was an autotile in that place and 0 would mean no autotile at all) in order to figure out which part of the autotile I should pick. Say I have an autotile with the byte 10101001. With an if, I would know which part of the autotile I should pick(That required exhaustive tests to determine all the combinations).

Of course I believe that there is some formula to pick it automatically, but as I didn't know it and I didn't find it at the time, I just used if's

Thanks
Title: Re: Autotiles Question
Post by: Blizzard on December 02, 2012, 11:15:38 am
Here's our C++ code for that.

I have defined the ID arrays somewhere on top first.

static int _autotiles[6][8][4] = {
{{27, 28, 33, 34}, { 5, 28, 33, 34}, {27,  6, 33, 34}, { 5,  6, 33, 34},
{27, 28, 33, 12}, { 5, 28, 33, 12}, {27,  6, 33, 12}, { 5,  6, 33, 12}},
{{27, 28, 11, 34}, { 5, 28, 11, 34}, {27,  6, 11, 34}, { 5,  6, 11, 34},
{27, 28, 11, 12}, { 5, 28, 11, 12}, {27,  6, 11, 12}, { 5,  6, 11, 12}},
{{25, 26, 31, 32}, {25,  6, 31, 32}, {25, 26, 31, 12}, {25,  6, 31, 12},
{15, 16, 21, 22}, {15, 16, 21, 12}, {15, 16, 11, 22}, {15, 16, 11, 12}},
{{29, 30, 35, 36}, {29, 30, 11, 36}, { 5, 30, 35, 36}, { 5, 30, 11, 36},
{39, 40, 45, 46}, { 5, 40, 45, 46}, {39,  6, 45, 46}, { 5,  6, 45, 46}},
{{25, 30, 31, 36}, {15, 16, 45, 46}, {13, 14, 19, 20}, {13, 14, 19, 12},
{17, 18, 23, 24}, {17, 18, 11, 24}, {41, 42, 47, 48}, { 5, 42, 47, 48}},
{{37, 38, 43, 44}, {37,  6, 43, 44}, {13, 18, 19, 24}, {13, 14, 43, 44},
{37, 42, 43, 48}, {17, 18, 47, 48}, {13, 18, 43, 48}, { 1,  2,  7,  8}}
};


And this is how they are used:

// y, x and j are simply ints, iterated from 0 to 6, 8 and 4 respectively
int position = _autotiles[y][x][j] - 1;
int tx = x * 32 + j % 2 * 16;
int ty = y * 32 + j / 2 * 16;
int sx = position % 6 * 16;
int sy = position / 6 * 16;
generated->bltOver(tx, ty, autotile, sx, sy, 16, 16);
if (animated)
{
generated->bltOver(tx, ty + 192, autotile, sx + 96, sy, 16, 16);
generated->bltOver(tx, ty + 384, autotile, sx + 192, sy, 16, 16);
generated->bltOver(tx, ty + 576, autotile, sx + 288, sy, 16, 16);
}


Bitmap::bltOver simply overwrites the already existing pixels, nothing special. "autotile" is a the actual bitmap loaded from the file (the one that is 96x128 pixels) and "generated" is the bitmap that is put together for rendering. It looks the same like the generated bitmap that you can view in the RMXP editor when you open an autotile in a tileset setting.
Title: Re: Autotiles Question
Post by: Apidcloud on December 02, 2012, 12:04:56 pm
Could you just explain what _autotiles is storing? What do those values mean exactly?

And how did you come up with the formula? did you write down the possible combinations and then made a formula?
Title: Re: Autotiles Question
Post by: Blizzard on December 02, 2012, 12:25:03 pm
I think F0 put all of this together when he wrote his custom Tilemap class. The _autotiles variable has all tile IDs that are used for autotiles. IDK how the first author figured this out (or who he is in particular), he probably took a look at how it looked like in RMXP's preview window and put all numbers together.
Title: Re: Autotiles Question
Post by: Apidcloud on December 02, 2012, 12:39:00 pm
No clue how he figured it out as well but I'm glad to know that there is a standard way  :haha:
I just thought the formula you used was made by yourselves  :P

Thanks