Advertisement

Syntax Question for Tile-Based Engine

Started by April 05, 2000 01:24 PM
59 comments, last by Nazrix 24 years, 8 months ago
I have a question about a tile-based game I'm working on. Actually it's the tile engine in Tricks of The Windows Game Programming Gurus. It's really a syntax question more than anything else. He initializes the world with this code.
    
char *world[21]=
{
"111111111111111111111111111111",
"100000000000000000000000000001",
"100002222220000000000000077701",
"100002222223333333333000077701",
"100002222227777777773000070001",
"100002222227777777773000070001",
"100000000377777777773000070001",
"107777700377777777773000070001",
"177777770377777777773000770001",
"107777700377777777773007700001",
"100777770377777777773777000001",
"100000707377777777773000000001",
"100007777377777777773000000001",
"100000000302222777773000000001",
"100000000332222777773000000001",
"100000000002222333333000000001",
"100000666666666666666666600001",
"100000800000000000000000800001",
"100000800000000000000000800001",
"100000000000000000000000000001",
"111111111111111111111111111111",
};
    
I was wondering how I would change the world later on in the code...like if you walk off of this map and I want to load the next set of tiles. I can't get the syntax right. I'm a little rusty on pointers. So, I just want to do something like world[21]={212121212...}; to load the new set of tiles. Just not sure about syntax... Thanks in advance... Edited by - Nazrix on 4/18/00 1:03:07 PM Edited by - Nazrix on 6/6/00 12:19:15 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
It's better to load the tilemap from a file, but if you insist...


//Init the tilemap (this only works if world is a globabl var)

char *world[21]=
{
"111111111111111111111111111111",
"100000000000000000000000000001",
"100002222220000000000000077701",
"100002222223333333333000077701",
"100002222227777777773000070001",
"100002222227777777773000070001",
"100000000377777777773000070001",
"107777700377777777773000070001",
"177777770377777777773000770001",
"107777700377777777773007700001",
"100777770377777777773777000001",
"100000707377777777773000000001",
"100007777377777777773000000001",
"100000000302222777773000000001",
"100000000332222777773000000001",
"100000000002222333333000000001",
"100000666666666666666666600001",
"100000800000000000000000800001",
"100000800000000000000000800001",
"100000000000000000000000000001",
"111111111111111111111111111111",
};

//If you want to change the tilemap later on, just call the function change_tile_map() to change it.

void change_tile_map(void)
{
world[0] = "111161511111111811111711111111";
world[1] = "2221615111111642311111711111111";
world[2] = "100000800000000000000000800001";

// and so on...
}



/. Muzzafarath

Edited by - Muzzafarath on 4/5/00 1:43:46 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Advertisement
of course, the best way is to not have world data hard-coded like that, but as long as ''worlds'' are same dimensions you can do:

world[21] = "212232...

which should work the same way.
again, you should really look into some other method as this is only useful for screwing around in a small world. anything larger than a few screens and you''re likely to have problems.

crazy166

some people think i'm crazy, some people know it
dontcha hate it when two people reply at the same time?

crazy166

some people think i'm crazy, some people know it
I don''t mind two posts at the same time. Two answers are better than one.

Thanks, that really helped a lot. Why exactly is it a better idea to do it from a file. Will it run out of memory or something? Also, do people generally make a file for each set of tiles?

Thanks again
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Storing your maps in files is generally a good idea for two reasons. One, it cuts down on your executable size. That''ll help for cacheing and stuff like that(I think). And two, having maps in seperate files means you can change maps without having to re-compile. That also means you can use tools to create your maps. That helps out a bit too.

Jonathan
Advertisement


If you need several maps and they are bigger than 100 x 100, then you really need an editor. But it is alot of work to make one. Maybe some can be found for free on the net.


-- There IS something rotten in the state of Denmark --
-------------Ban KalvinB !
Actually, editors don''t really take that long, if you are good at Windows programming (not MFC). Well, you could use MFC if you wanted.

altair
altair734@yahoo.com
biggins.mit.edu/altair734
altairaltair734@yahoo.comwww.geocities.com/altair734
Editors are quite easy to do.

/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Well, I think I've done my share of messing around with the tiles hard-coded in the program. Could someone give me a little code to get me started in loading a program with the tile info in it. I know I use fopen and so forth, but I'm not sure exactly how to do it.

Thanks

Edited by - Nazrix on 4/10/00 9:42:54 AM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi

This topic is closed to new replies.

Advertisement