2 // C Implementation: level
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
9 // Copyright: See COPYING file that comes with this distribution
20 /* Load data for this level: */
22 void loadlevel(st_level* plevel, char *subset, int level)
32 filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20) + strlen(subset));
33 sprintf(filename, "%s/levels/%s/level%d.dat", DATA_PREFIX, subset, level);
34 fi = fopen(filename, "r");
45 /* Load header info: */
50 strcpy(plevel->name, str);
51 plevel->name[strlen(plevel->name)-1] = '\0';
55 strcpy(plevel->theme, str);
56 plevel->theme[strlen(plevel->theme)-1] = '\0';
60 /* (Time to beat level) */
62 plevel->time_left = atoi(str);
64 /* (Song file for this level) */
65 fgets(str, sizeof(plevel->song_title), fi);
66 strcpy(plevel->song_title, str);
67 plevel->song_title[strlen(plevel->song_title)-1] = '\0';
71 /* (Level background color) */
73 plevel->bkgd_red = atoi(str);
75 plevel->bkgd_green= atoi(str);
77 plevel->bkgd_blue = atoi(str);
81 plevel->width = atoi(str);
84 /* Allocate some space for the line-reading! */
86 line = (char *) malloc(sizeof(char) * (plevel->width + 5));
89 fprintf(stderr, "Couldn't allocate space to load level data!");
94 /* Load the level lines: */
96 for (y = 0; y < 15; y++)
98 if(fgets(line, plevel->width + 5, fi) == NULL)
100 fprintf(stderr, "Level %s isn't complete!\n",plevel->name);
103 line[strlen(line) - 1] = '\0';
104 plevel->tiles[y] = strdup(line);
111 /* Load a level-specific graphic... */
113 SDL_Surface * load_level_image(char* theme, char * file, int use_alpha)
117 snprintf(fname, 21024, "%simages/themes/%s/%s", DATA_PREFIX, theme, file);
119 return(load_image(fname, use_alpha));