void
Level::save(const std::string& filename)
{
-#if 0
- LispReader* level = LispReader::load(filename, "supertux-level");
+ ofstream file(filename.c_str(), ios::out);
+ LispWriter* writer = new LispWriter(file);
- int version = 1;
- level->read_int("version", version);
- if(version == 1) {
- load_old_format(*level);
- return;
- }
+ writer->write_comment("Level made using SuperTux's built-in Level Editor");
- for(lisp_object_t* cur = level->get_lisp(); !lisp_nil_p(cur);
- cur = lisp_cdr(cur)) {
- std::string token = lisp_symbol(lisp_car(lisp_car(cur)));
- lisp_object_t* data = lisp_car(lisp_cdr(lisp_car(cur)));
- LispReader reader(lisp_cdr(lisp_car(cur)));
+ writer->start_list("supertux-level");
- if(token == "name") {
- name = lisp_string(data);
- } else if(token == "author") {
- author = lisp_string(data);
- } else if(token == "time") {
- time_left = lisp_integer(data);
- } else if(token == "sector") {
- Sector* sector = new Sector;
- sector->parse(reader);
- add_sector(sector);
- } else {
- std::cerr << "Unknown token '" << token << "' in level file.\n";
- continue;
- }
- }
-
- delete level;
-#endif
+ int version = 2;
+ writer->write_int("version", version);
+
+ writer->write_string("name", name);
+ writer->write_string("author", author);
+ writer->write_int("time", time_left);
+
+ for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
+ i->second->write(*writer);
+
+ writer->end_list("supertux-level");
+
+ delete writer;
+ file.close();
}
Level::~Level()
}
context.draw_surface_part(cursor, Vector(w*cur_frame, h*cur_state), Vector(w,
- h), Vector(x-mid_x, y-mid_y), LAYER_FOREGROUND1+100);
+ h), Vector(x-mid_x, y-mid_y), LAYER_GUI+100);
}
DrawingContext::DrawingContext()
{
+transform.draw_effect = NONE_EFFECT;
}
DrawingContext::~DrawingContext()
request.request_data = const_cast<Surface*> (surface);
request.pos = transform.apply(position);
request.drawing_effect = drawing_effect;
+ request.drawing_effect = transform.draw_effect | drawing_effect;
drawingrequests.push_back(request);
}
transformstack.pop_back();
}
+void
+DrawingContext::set_drawing_effect(int effect)
+{
+ transform.draw_effect = effect;
+}
void push_transform();
void pop_transform();
+ /** apply that effect in the next draws (effects are listed on surface.h) */
+ void set_drawing_effect(int effect);
+
private:
class Transform
{
{
return v - translation;
}
+
+ int draw_effect;
};
/// the transform stack
/* Handle all possible collisions. */
collision_handler();
+ update_game_objects();
+}
+
+void
+Sector::update_game_objects()
+{
/** cleanup marked objects */
for(std::vector<GameObject*>::iterator i = gameobjects.begin();
i != gameobjects.end(); /* nothing */) {
gameobjects.push_back(*i);
}
gameobjects_new.clear();
-
}
void
void activate(const std::string& spawnpoint = "main");
void action(float elapsed_time);
+ void update_game_objects();
+
void draw(DrawingContext& context);
/// adds a gameobject
st_menu();
loadshared();
- if (launch_leveleditor_mode && level_startup_file)
+ if (launch_leveleditor_mode)
{
- // TODO
- // leveleditor(level_startup_file);
+ LevelEditor leveleditor;
+
+ if(level_startup_file)
+ leveleditor.run(level_startup_file);
+ else
+ leveleditor.run();
}
else if (level_startup_file)
{
const Vector& pos, int layer);
static std::set<TileGroup>* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set<TileGroup>; }
+
+ unsigned int total_ids()
+ { return tiles.size(); }
+
Tile& get(unsigned int id) {
if(id < tiles.size())
size_t get_height() const
{ return height; }
+
+ int get_layer() const
+ { return layer; }
bool is_solid() const
{ return solid; }