PROBLEM SOLVED. I had to make the array 22 x 22, and the for loops < 22. I realized the pack_fread function counts in the line changes as two chars. Anyway, thanks for the help guys.
Hi, I´ve been starring at this code the whole day, so I was hoping someone with fresh eyes could help me out why the tiles are not lining up properly on screen. I suspect it has something to do with the size of the maptab array or loadbuffer.
the tiles are 32 x 24 and the screen is 640 x 380 (20 x 20 = 400 tiles on screen).
1 | |
2 | |
3 | int maptab[20][20]; |
4 | |
5 | void mapload() |
6 | { |
7 | char loadbuffer[400]; |
8 | |
9 | PACKFILE *themap; |
10 | themap = pack_fopen("tiletest.txt", "r"); |
11 | pack_fread(loadbuffer, 400, themap); |
12 | pack_fclose(themap); |
13 | |
14 | int x; |
15 | int y; |
16 | int z = 0; |
17 | |
18 | for (y = 0; y < 20; y++) |
19 | for (x = 0; x < 20; x++) |
20 | { |
21 | maptab[ y ][ x ] = loadbuffer[z]; |
22 | z++; |
23 | } |
24 | } |
25 | |
26 | void tilemapping() |
27 | { |
28 | int x = 0; |
29 | int y = 0; |
30 | |
31 | for (y = 0; y < 20; y++) |
32 | for (x = 0; x < 20; x++) |
33 | if( maptab[ y ][ x ] == 1) blit(plat_cheq, buffer, 0, 0, x * 32, y * 24, 32, 24); |
34 | |
35 | } |
Here is the map file (20 x 20):
1 | |
2 | 11111111111111111111 |
3 | 00000000000000000000 |
4 | 00000000000000000000 |
5 | 00000000000000000000 |
6 | 00000000000000000000 |
7 | 00000000110000000000 |
8 | 00000000000000000000 |
9 | 00000000000110000000 |
10 | 00000000000000000000 |
11 | 00000000000000110000 |
12 | 00000000000000000000 |
13 | 00000000000000000110 |
14 | 00000000000000000000 |
15 | 00000000000000110000 |
16 | 00000000000000000000 |
17 | 00000000000110000000 |
18 | 00000000000000000000 |
19 | 00000000110000000000 |
20 | 00000000000000000000 |
21 | 11111111111111111111 |
tiles are not lining up properly on screen
What you mean exactly? Can you maybe provide a screenshot of what's going wrong?
Regards
If you're waiting for diamond-shape style tilemap, you're not using the right formulae.
Other thing: your storing-loading routine is not common ... maybe you should re-thing to it
I figured some things out, I changed
if( maptab[ y ][ x ] == 1)
to
if( maptab[ y ][ x ] == '1')
as I remembered a char is 8 numbers, and the maptab array to char allso.
but it still looks a bit twisted:
http://www.cc.puv.fi/~e0400536/tile.JPG
this works:
1 | |
2 | void tilemapping() |
3 | { |
4 | int maptab[20][20] = { |
5 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
6 | 1, 1, 1, 1 }, |
7 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
8 | 0, 0, 0, 0 }, |
9 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
10 | 0, 0, 0, 0 }, |
11 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
12 | 0, 0, 0, 0 }, |
13 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
14 | 0, 0, 0, 0 }, |
15 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, |
16 | 0, 0, 0, 0 }, |
17 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
18 | 0, 0, 0, 0 }, |
19 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, |
20 | 0, 0, 0, 0 }, |
21 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
22 | 0, 0, 0, 0 }, |
23 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, |
24 | 0, 0, 0, 0 }, |
25 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
26 | 0, 0, 0, 0 }, |
27 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
28 | 0, 1, 1, 0 }, |
29 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
30 | 0, 0, 0, 0 }, |
31 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, |
32 | 0, 0, 0, 0 }, |
33 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
34 | 0, 0, 0, 0 }, |
35 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, |
36 | 0, 0, 0, 0 }, |
37 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
38 | 0, 0, 0, 0 }, |
39 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, |
40 | 0, 0, 0, 0 }, |
41 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
42 | 0, 0, 0, 0 }, |
43 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
44 | 1, 1, 1, 1 } |
45 | }; |
46 | |
47 | int x = 0; |
48 | int y = 0; |
49 | |
50 | for (y = 0; y < 20; y++) |
51 | for (x = 0; x < 20; x++) |
52 | if( maptab[ y ][ x ] == 1) blit(plat_cheq, buffer, 0, 0, x * 32, y * 24, 32, 24); |
53 | |
54 | } |
it looks like this (this is what it should look like)
http://www.cc.puv.fi/~e0400536/tile2.JPG
but, I specifically would want to load my maps from files.
PROBLEM SOLVED. I had to make the array 22 x 22, and the for loops < 22. I realized the pack_fread function counts in the line changes as two chars. Anyway, thanks for the help guys.