A few changes to make the code ready for the new level editor.
authorRicardo Cruz <rick2@aeiou.pt>
Mon, 28 Jun 2004 11:30:27 +0000 (11:30 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Mon, 28 Jun 2004 11:30:27 +0000 (11:30 +0000)
Major changes:
- Level's save() works. Still doesn't save the game properly.
- added a set_drawing_effect() for DrawingContext. Will apply it to the following drawings. Works with pop/push_transform.

SVN-Revision: 1514

src/level.cpp
src/mousecursor.cpp
src/screen/drawing_context.cpp
src/screen/drawing_context.h
src/sector.cpp
src/sector.h
src/supertux.cpp
src/tile_manager.h
src/tilemap.h

index 3470547..a3d5a44 100644 (file)
@@ -100,40 +100,27 @@ Level::load_old_format(LispReader& reader)
 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()
index ee0a57d..177f2f7 100644 (file)
@@ -89,5 +89,5 @@ void MouseCursor::draw(DrawingContext& context)
     }
 
   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);
 }
index 9a22274..135d9a1 100644 (file)
@@ -27,6 +27,7 @@
 
 DrawingContext::DrawingContext()
 {
+transform.draw_effect = NONE_EFFECT;
 }
 
 DrawingContext::~DrawingContext()
@@ -46,6 +47,7 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position,
   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);
 }
@@ -341,3 +343,8 @@ DrawingContext::pop_transform()
   transformstack.pop_back();
 }
 
+void
+DrawingContext::set_drawing_effect(int effect)
+{
+  transform.draw_effect = effect;
+}
index 1c62419..ceb9ea2 100644 (file)
@@ -83,6 +83,9 @@ public:
   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
   {
@@ -93,6 +96,8 @@ private:
     {
       return v - translation;
     }
+
+    int draw_effect;
   };
 
   /// the transform stack
index 1636118..5752860 100644 (file)
@@ -332,6 +332,12 @@ Sector::action(float elapsed_time)
   /* 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 */) {
@@ -407,7 +413,6 @@ Sector::action(float elapsed_time)
           gameobjects.push_back(*i);
   }
   gameobjects_new.clear();
-
 }
 
 void
index 4db5285..c8aa0b3 100644 (file)
@@ -69,6 +69,8 @@ public:
   void activate(const std::string& spawnpoint = "main");
 
   void action(float elapsed_time);
+  void update_game_objects();
+
   void draw(DrawingContext& context);
 
   /// adds a gameobject
index 588639a..7c46b74 100644 (file)
@@ -58,10 +58,14 @@ int main(int argc, char * argv[])
     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)
     {
index a55fcb8..a72777b 100644 (file)
@@ -61,6 +61,10 @@ class TileManager
       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())
index 6f82642..fa39f2a 100644 (file)
@@ -68,6 +68,9 @@ public:
 
   size_t get_height() const
   { return height; }
+
+  int get_layer() const
+  { return layer; }
   
   bool is_solid() const
   { return solid; }