-Level::init_defaults()
-{
- name = "UnNamed";
- author = "UnNamed";
- theme = "antarctica";
- song_title = "Mortimers_chipdisko.mod";
- bkgd_image = "arctis.png";
- width = 21;
- start_pos_x = 100;
- start_pos_y = 170;
- time_left = 100;
- gravity = 10.;
- bkgd_top.red = 0;
- bkgd_top.green = 0;
- bkgd_top.blue = 0;
- bkgd_bottom.red = 255;
- bkgd_bottom.green = 255;
- bkgd_bottom.blue = 255;
- endpos = 0;
-
- for(int i = 0; i < 15; ++i)
- {
- ia_tiles[i].resize(width+1, 0);
- ia_tiles[i][width] = (unsigned int) '\0';
-
- for(int y = 0; y < width; ++y)
- ia_tiles[i][y] = 0;
-
- bg_tiles[i].resize(width+1, 0);
- bg_tiles[i][width] = (unsigned int) '\0';
- for(int y = 0; y < width; ++y)
- bg_tiles[i][y] = 0;
-
- fg_tiles[i].resize(width+1, 0);
- fg_tiles[i][width] = (unsigned int) '\0';
- for(int y = 0; y < width; ++y)
- fg_tiles[i][y] = 0;
- }
-}
-
-int
-Level::load(const std::string& subset, int level)
-{
- char filename[1024];
-
- // Load data file:
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level);
- if(!faccessible(filename))
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset.c_str(), level);
-
- return load(filename);
-}
-
-int
-Level::load(const std::string& filename)
-{
- FILE * fi;
- lisp_object_t* root_obj = 0;
- fi = fopen(filename.c_str(), "r");
- if (fi == NULL)
- {
- perror(filename.c_str());
- return -1;
- }
-
- lisp_stream_t stream;
- lisp_stream_init_file (&stream, fi);
- root_obj = lisp_read (&stream);
-
- if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
- {
- printf("World: Parse Error in file %s", filename.c_str());
- }
-
- vector<int> ia_tm;
- vector<int> bg_tm;
- vector<int> fg_tm;
-
- int version = 0;
- if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
- {
- LispReader reader(lisp_cdr(root_obj));
- reader.read_int("version", &version);
- reader.read_int("width", &width);
- if (!reader.read_int("start_pos_x", &start_pos_x)) start_pos_x = 100;
- if (!reader.read_int("start_pos_y", &start_pos_y)) start_pos_y = 170;
- reader.read_int("time", &time_left);
-
- reader.read_int("bkgd_top_red", &bkgd_top.red);
- reader.read_int("bkgd_top_green", &bkgd_top.green);
- reader.read_int("bkgd_top_blue", &bkgd_top.blue);
-
- reader.read_int("bkgd_bottom_red", &bkgd_bottom.red);
- reader.read_int("bkgd_bottom_green", &bkgd_bottom.green);
- reader.read_int("bkgd_bottom_blue", &bkgd_bottom.blue);
-
- reader.read_float("gravity", &gravity);
- reader.read_string("name", &name);
- reader.read_string("author", &author);
- reader.read_string("theme", &theme);
- reader.read_string("music", &song_title);
- reader.read_string("background", &bkgd_image);
- reader.read_string("particle_system", &particle_system);
- reader.read_int_vector("background-tm", &bg_tm);
-
- if (!reader.read_int_vector("interactive-tm", &ia_tm))
- reader.read_int_vector("tilemap", &ia_tm);
-
- reader.read_int_vector("foreground-tm", &fg_tm);
-
- { // Read ResetPoints
- lisp_object_t* cur = 0;
- if (reader.read_lisp("reset-points", &cur))
- {
- while (!lisp_nil_p(cur))
- {
- lisp_object_t* data = lisp_car(cur);
-
- ResetPoint pos;
-
- LispReader reader(lisp_cdr(data));
- if (reader.read_int("x", &pos.x)
- && reader.read_int("y", &pos.y))
- {
- reset_points.push_back(pos);
- }
-
- cur = lisp_cdr(cur);
- }
- }