Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » tiling problem

This thread is locked; no one can reply to it. rss feed Print
tiling problem
TurboJudas
Member #7,039
March 2006
avatar

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 
3int maptab[20][20];
4 
5void 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 
26void 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 
211111111111111111111
300000000000000000000
400000000000000000000
500000000000000000000
600000000000000000000
700000000110000000000
800000000000000000000
900000000000110000000
1000000000000000000000
1100000000000000110000
1200000000000000000000
1300000000000000000110
1400000000000000000000
1500000000000000110000
1600000000000000000000
1700000000000110000000
1800000000000000000000
1900000000110000000000
2000000000000000000000
2111111111111111111111

umperio
Member #3,474
April 2003
avatar

Quote:

tiles are not lining up properly on screen

What you mean exactly? Can you maybe provide a screenshot of what's going wrong?

Regards

GullRaDriel
Member #3,861
September 2003
avatar

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

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

TurboJudas
Member #7,039
March 2006
avatar

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 
2void tilemapping()
3{
4 int maptab[20][20] = {
5{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
61, 1, 1, 1 },
7{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80, 0, 0, 0 },
9{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100, 0, 0, 0 },
11{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120, 0, 0, 0 },
13{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
140, 0, 0, 0 },
15{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
160, 0, 0, 0 },
17{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
180, 0, 0, 0 },
19{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
200, 0, 0, 0 },
21{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220, 0, 0, 0 },
23{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
240, 0, 0, 0 },
25{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
260, 0, 0, 0 },
27{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
280, 1, 1, 0 },
29{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
300, 0, 0, 0 },
31{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
320, 0, 0, 0 },
33{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
340, 0, 0, 0 },
35{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
360, 0, 0, 0 },
37{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
380, 0, 0, 0 },
39{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
400, 0, 0, 0 },
41{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
420, 0, 0, 0 },
43{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
441, 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.

Go to: