Skip to main content
gamedev.net
🔒 Locked

map loading

Started by lpsoftware Jul 12, 2000 at 7:41 PM 9 replies 500+ views
Original Post
lpsoftware
lpsoftware
Hi. Until now, I haven''t really been using any other maps except the one "test map" in my tile-based game, and I''ve hit a problem. By the way, I am not loading the maps from an external file, they are all declared in the source. I have the 2d map array variable called map[40][40] and I define it in a initialization function. Dandy. In my game, there''s a "pick-a-level-screen" similar to that of DxBall 2, and once a level is picked from the screen, there''s a call to the map loading function which goes something like this. //... if (level == 1) char map[40][40] = ... //declare the map. else if (level == 2) char map[40][40] = ... //declare the map for the 2nd level. //... From there, the main game loop should be entered and the map that was loaded into map[40][40] should be used for the gameply. PROBLEM: I don''t know what the problem is (of course!), but no tiles are being drawn, as if the map was never declared. And, yes, I''m sure that in the level picking screen, the int variable level is assigned to the map that was picked. And, yes, I use the same method for defining a map in an initialization function, for example, as I did in the map loading function. And, yes, I know that this routine (even if it did work) would not be good at all, but I just want to get this done. I feel really stupid for asking this question, as the answer is probably a stupid thing that I did for the assigning of the new maps. Thank you very much, Martin
______________Martin EstevaolpSoftware
Julio
Julio
try using the 'new' keyword. this creates a "new" array.
    
new char map[40][40]=...

or something like that

JoeMont001@aol.com www.polarisoft.n3.net

Edited by - Julio on July 12, 2000 9:01:21 PM
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
lpsoftware
lpsoftware
Julio: Thanks for the suggestion, but it didn''t work for some reason. I think my problem is that 2dimensional arrays (if not all arrays) are constant. I''ll keep working on it.

Any more suggestions?

Thanks,
Martin
______________Martin EstevaolpSoftware
RoTTer
RoTTer
Hey lpsoftware.

Well, Im not sure what could be wrong... Could ya post a bit of your code?

Like one whole 40x40 declaration of the map, or something. Maybe the prototype of this function you posted a bit, the variable declaration, the first "if (level == 1)", the last and the function closing.

Just a bit more of code so we can analyze it and see if something is wrong .
Ah and use (source) + (/source), its much more readable than (code) + (/code). Change the ()''s to the proper chars that you know.

Cya,
-RoTTer
RoTTer
RoTTer
Hey

Nice point, anon poster .

Im not sure also if thats the problem but is very likely it is, or the compiler wouldnt allow multiple "char map[40][40]" if the var isnt killed after the if (the compiler doesnt know it will fail in the other ifs... or does it (cause of the else''s)? oh well).
Anyway, it seems anon poster got whats the problem already. Confirmation, lp?

Cya,
-RoTTer
lpsoftware
lpsoftware
Anon Poster, thanks for the suggestion, but I tried doing just



map[40][40] = //...



before I posted the question. It still doesn''t work that way. However, I figured out a new way to do it:



for (int x = 0; x < SCR_WIDTH; x++) {
for (int y = 0; y < SCR_HEIGHT; y++) {

level1map[x][y] = map[x][y];
}
}



...where level1map is the map defined in an initilization function for "level 1" and map is the map used throughout the gameplay and for all of my functions. I''m supposing that since I''ve been changing individual members of my 2d map array throughout the whole development process, I can do it here. For some reason, I can''t change the thing as a whole, but I can change the individual members. BTW, this isn''t tested yet so I''m not sure if it''s 99% correct, or 1% for that matter.

Anyway, more suggestios are welcome and thanks for the help.

Martin
______________Martin EstevaolpSoftware
Gladiator
Gladiator
shouldn''t it be

map[x][y] = level1map[x][y];

??
glROCKs();
glROCKs();
Why don''t you just work with dynamic array''s.

    
int Width, Height;
int **Map;
//read map width and height and put them in the vars


//create map array


Map = new int*[Height];
for(int i=0; i<Height; i++)
Map<i> = new int[i][Width];



I think this should work, though I''m not sure since I haven''t been able to test it.


The Rock

-BAD software-
The Rock
lpsoftware
lpsoftware
Just lettin'' you all know that I tried my new method that I came up with (see above) and it works just fine.

Martin
______________Martin EstevaolpSoftware

Topic Locked

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

Sign in to reply to this topic.