Table. Array. Same difference. :P
I'm having a total brain fart on the math for converting an (x,y) index into a single (x) index.
The units of measure are arbitrary. They can be as small as a pixel to as big as a house...
Given:
- A source grid of 20x10 tiles labeled 0 through 199 starting at the upper left at size 32x32 for each tile.
- A destination grid of 20x1500 tiles starting at zero with the same size tiles and orientation.
- A series of numbers indicating an index from the source grid; i.e 3, 3, 3, 48, 47, 158; where each index's location (zero-based) in the list is the destination tile placement.
Problem:
Using the series of numbers from first to last, place each source tile in its proper location on the destination grid.
For those of you that know C++ here's my attempt:
A representative sample of the MAP definition to follow because it's massive.
//blit Signature void blit(BITMAP* source, BITMAP* destination, int source_x, int source_y, int dest_x, int dest_y, int width, int height); for(int map_pos = 0; (map_pos < L1TW * L1TH); ++map_pos) { blit(tiles->GetImage(), background->GetImage(), ((MAP[map_pos] % 20) - 1) * L1FW, ((MAP[map_pos] / 10) - 1) * L1FH, (map_pos % L1TH) * L1FH, (map_pos / L1TW) * L1FW, L1FW, L1FH); }
#define L1TW 20 #define L1TH 1500 #define L1FW 32 #define L1FH 32 #define L1PW (L1TW * L1FW) #define L1PH (L1TH * L1FH) #define L1A (L1TW * L1TH) const int MAP[] = { 3, 3, 3, 3, 3, 3, 3, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 23, 23, 23, 23, 23, 23, 23, 23, 10, 1, 57, 1, 49, 23, 23, 23, 23, 23, 23, 23, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 166, 158, 158, 166, 158, 166, 166, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 166, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 166, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 166, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 22, 22, 22, 22, 22, 22, 22, 50, 1, 57, 1, 30, 22, 22, 22, 22, 22, 22, 22, 22, 3, 3, 3, 3, 3, 3, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 3, 3, 99, 99, 99, 99, 99, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 94, 94, 94, 3, 99, 127, 99, 127, 99, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 94, 95, 94, 3, 99, 127, 127, 127, 99, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 94, 94, 94, 3, 99, 127, 99, 127, 99, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 3, 3, 99, 99, 99, 99, 99, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 48, 1, 57, 1, 47, 3, 3, 3, 3, 3, 3, 3, 3 };
EDIT
Here's the corrected math:
for(int map_pos = 0; (map_pos < L1TW * L1TH); ++map_pos) { blit(tiles->GetImage(), background->GetImage(), (MAP[map_pos] % L1TW) * L1FW, (MAP[map_pos] / L1TW) * L1FH, (map_pos % L1TW) * L1FW, (map_pos / L1TW) * L1FH, L1FW, L1FH); }