bkgd_image = "arctis.jpg";
width = 0;
height = 0;
- start_pos_x = 100;
- start_pos_y = 170;
+ start_pos.x = 100;
+ start_pos.y = 170;
time_left = 100;
gravity = 10.;
- back_scrolling = false;
- hor_autoscroll_speed = 0;
bkgd_speed = 50;
bkgd_top.red = 0;
bkgd_top.green = 0;
if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
{
- printf("World: Parse Error in file %s", filename.c_str());
+ lisp_free(root_obj);
+ std::cout << "World: Parse Error in file '" << filename
+ << "'.\n";
return -1;
}
reader.read_int("version", &version);
if(!reader.read_int("width", &width))
st_abort("No width specified for level.", "");
- 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;
+ if (!reader.read_float("start_pos_x", &start_pos.x)) start_pos.x = 100;
+ if (!reader.read_float("start_pos_y", &start_pos.y)) start_pos.y = 170;
time_left = 500;
if(!reader.read_int("time", &time_left)) {
- printf("Warning no time specified for level.\n");
+ printf("Warning: no time specified for level.\n");
}
height = 15;
- reader.read_int("height", &height);
-
- back_scrolling = false;
- reader.read_bool("back_scrolling", &back_scrolling);
-
- hor_autoscroll_speed = 0;
- reader.read_float("hor_autoscroll_speed", &hor_autoscroll_speed);
+ if(!reader.read_int("height", &height)) {
+ printf("Warning: no height specified for level.\n");
+ }
bkgd_speed = 50;
reader.read_int("bkgd_speed", &bkgd_speed);
-
bkgd_top.red = bkgd_top.green = bkgd_top.blue = 0;
reader.read_int("bkgd_red_top", &bkgd_top.red);
}
}
- { // Read BadGuys
+ { // Read Objects
lisp_object_t* cur = 0;
if (reader.read_lisp("objects", &cur))
{
}
}
-#if 0 // TODO fix this or remove it
- // Convert old levels to the new tile numbers
- if (version == 0)
- {
- std::map<char, int> transtable;
- transtable['.'] = 0;
- transtable['x'] = 104;
- transtable['X'] = 77;
- transtable['y'] = 78;
- transtable['Y'] = 105;
- transtable['A'] = 83;
- transtable['B'] = 102;
- transtable['!'] = 103;
- transtable['a'] = 84;
- transtable['C'] = 85;
- transtable['D'] = 86;
- transtable['E'] = 87;
- transtable['F'] = 88;
- transtable['c'] = 89;
- transtable['d'] = 90;
- transtable['e'] = 91;
- transtable['f'] = 92;
-
- transtable['G'] = 93;
- transtable['H'] = 94;
- transtable['I'] = 95;
- transtable['J'] = 96;
-
- transtable['g'] = 97;
- transtable['h'] = 98;
- transtable['i'] = 99;
- transtable['j'] = 100
- ;
- transtable['#'] = 11;
- transtable['['] = 13;
- transtable['='] = 14;
- transtable[']'] = 15;
- transtable['$'] = 82;
- transtable['^'] = 76;
- transtable['*'] = 80;
- transtable['|'] = 79;
- transtable['\\'] = 81;
- transtable['&'] = 75;
-
- int x = 0;
- int y = 0;
- for(std::vector<int>::iterator i = ia_tm.begin(); i != ia_tm.end(); ++i)
- {
- if (*i == '0' || *i == '1' || *i == '2')
- {
- badguy_data.push_back(BadGuyData(static_cast<BadGuyKind>(*i-'0'),
- x*32, y*32, false));
- *i = 0;
- }
- else
- {
- std::map<char, int>::iterator j = transtable.find(*i);
- if (j != transtable.end())
- *i = j->second;
- else
- printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i);
- }
- ++x;
- if (x >= width)
- {
- x = 0;
- ++y;
- }
+ { // Read Camera
+ lisp_object_t* cur = 0;
+ if (reader.read_lisp("camera", &cur))
+ {
+ LispReader reader(cur);
+ if(world) {
+ world->camera->read(reader);
}
- }
-#endif
+ }
+ }
}
lisp_free(root_obj);
char str[80];
/* Save data file: */
- sprintf(str, "/levels/%s/", subset.c_str());
+ snprintf(str, sizeof(str), "/levels/%s/", subset.c_str());
fcreatedir(str);
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(),
- level);
+ snprintf(filename, sizeof(filename),
+ "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level);
if(!fwriteable(filename))
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(),
- subset.c_str(), level);
+ snprintf(filename, sizeof(filename), "%s/levels/%s/level%d.stl",
+ datadir.c_str(), subset.c_str(), level);
std::ofstream out(filename);
if(!out.good()) {
writer.write_int("time", time_left);
writer.write_int("width", width);
writer.write_int("height", height);
- writer.write_bool("back_scrolling", back_scrolling);
- writer.write_float("hor_autoscroll_speed", hor_autoscroll_speed);
writer.write_float("gravity", gravity);
writer.write_int_vector("background-tm", bg_tiles);
writer.start_list("point");
writer.write_int("x", i->x);
writer.write_int("y", i->y);
+ writer.end_list("point");
}
writer.end_list("reset-points");
void
Level::resize(int new_width, int new_height)
{
- // first: resize height
- ia_tiles.resize(new_height * width, 0);
- bg_tiles.resize(new_height * width, 0);
- fg_tiles.resize(new_height * width, 0);
- height = new_height;
+ if(new_width < width) {
+ // remap tiles for new width
+ for(int y = 0; y < height && y < new_height; ++y) {
+ for(int x = 0; x < new_width; ++x) {
+ ia_tiles[y * new_width + x] = ia_tiles[y * width + x];
+ bg_tiles[y * new_width + x] = bg_tiles[y * width + x];
+ fg_tiles[y * new_width + x] = fg_tiles[y * width + x];
+ }
+ }
+ }
- // remap horizontal tiles for new width
- int np = 0;
- for(int y = 0; y < height; ++y) {
- for(int x = 0; x < new_width && x < width; ++x) {
- ia_tiles[np] = ia_tiles[y * width + x];
- bg_tiles[np] = bg_tiles[y * width + x];
- fg_tiles[np] = fg_tiles[y * width + x];
- np++;
+ ia_tiles.resize(new_width * new_height);
+ bg_tiles.resize(new_width * new_height);
+ fg_tiles.resize(new_width * new_height);
+
+ if(new_width > width) {
+ // remap tiles
+ for(int y = std::min(height, new_height)-1; y >= 0; --y) {
+ for(int x = new_width-1; x >= 0; --x) {
+ if(x >= width) {
+ ia_tiles[y * new_width + x] = 0;
+ bg_tiles[y * new_width + x] = 0;
+ fg_tiles[y * new_width + x] = 0;
+ } else {
+ ia_tiles[y * new_width + x] = ia_tiles[y * width + x];
+ bg_tiles[y * new_width + x] = bg_tiles[y * width + x];
+ fg_tiles[y * new_width + x] = fg_tiles[y * width + x];
+ }
+ }
}
}
- ia_tiles.resize(new_height * new_width);
- bg_tiles.resize(new_height * new_width);
- fg_tiles.resize(new_height * new_width);
-
+ height = new_height;
width = new_width;
}