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
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.
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.
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?
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.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more