LoadMap(map_id, g_levels[k].map);
int map[WORLDSIZE_Y][WORLDSIZE_X];
LoadMap(map_id, g_levels[k].map);
int map[WORLDSIZE_Y][WORLDSIZE_X];
Quote:Original post by fpsgamer
LoadMap should have the following signature:
LoadMap(int id, int map[][WORLDSIZE_X]);
void LoadMap(const char* name, int destination[][WORLDSIZE_X]){ FILE* map_data = fopen(name, "r"); if (!map_data) { WriteToLogFile("Error: Unable to open map file."); } for (int m = 0; m < WORLDSIZE_X; m++) { for (int n = 0; n < WORLDSIZE_Y; n++) { fscanf(map_data, "%d", &destination[n * WORLDSIZE_X + m]); } } fclose(map_data);}
void DrawTiles(){ // used to retrieve current tile int current_tile; // so we will know where to draw the tile SDL_Rect src, dest; // each tile is 32x32 src.w = 32; src.h = 32; for (int i = 0; i < WORLDSIZE_X; i++) { for (int j = 0; j < WORLDSIZE_Y; j++) { // retrive current tile current_tile = g_levels[g_current_level].map[j]; // determine where to render it onscreen src.x = current_tile * 32; src.y = 0; dest.x = OFFSET_X + i*32; dest.y = OFFSET_Y + j*32; // draw tile SDL_BlitSurface(g_tileset,&src,g_screen,&dest); } }}
for (int m = 0; m < WORLDSIZE_X; m++) // for each column{ for (int n = 0; n < WORLDSIZE_Y; n++) // for each row in column { fscanf(map_data, "%d", &destination[n][m]); }}
for (int n = 0; n < WORLDSIZE_Y; n++) // for each row...{ for (int m = 0; m < WORLDSIZE_X; m++) // for each column in row... { fscanf(map_data, "%d", &destination[n][m]); }}