Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D Map of Array

Started by Link Jul 18, 2003 at 9:38 AM 5 replies 850+ views
Original Post
Link
Link
I''ve made a 2d map, i don''t know if either to save it as an ANSI file text so an array like this: inside the file: int Map = {0,1,5,7,... ......... ......... } Or to save it into a bin file. Anyway Either in the first case and the second i don''t know how import it in my Game and save into a int array. P.S. I know C++ very good and read and write into a file but it is the first time i do this particular thing for a game.
Turt99
Turt99
if your doing it the first way, and actually having it with the int Map declaration, then you could just make that file a .h file and include it within all files that you needed to use the array.. However that would make it impossible to edit the map with out recompiling the game so it would probably not be the best Idea.

you will need to make some sort of format that you want your maps in and then right up a little text parser to grab all the values from the lines

FOLLOW ME ON TWITTER OR MY BLOG
Buster
Buster

*m = yourMapArray;
for (x=0; x<(mapSizeX*mapSizeY); x++,m++) {
writeToFile(*m);
}


reading the file is exactly the same, just read instead of write
Turt99
Turt99
quote:
Original post by Buster

*m = yourMapArray;
for (x=0; x<(mapSizeX*mapSizeY); x++,m++) {
writeToFile(*m);
}


reading the file is exactly the same, just read instead of write


this would just put a 1 value on each of the lines right?
so that each line you read in that the next value in the array...



Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
Link
Link
quote:
Original post by Buster

*m = yourMapArray;
for (x=0; x<(mapSizeX*mapSizeY); x++,m++) {
writeToFile(*m);
}


reading the file is exactly the same, just read instead of write



ok, but don't you think it is so rough?
make a file text very long, with much lines, also more of 20.000 !!!


[edited by - Link on July 18, 2003 11:31:11 AM]
Link
Link
ok, i want to opt for save the Array into a .h file. how can do it?

can someone give me an example of code to do it?
Link
Link
up

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.