Instead of setting the level to be flipped from the level file, it is now passed...
[supertux.git] / src / sector.cpp
index bd45014..4972ecc 100644 (file)
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <memory>
+#include <algorithm>
 #include <stdexcept>
 #include <iostream>
 #include <fstream>
 #include <stdexcept>
 
+#include "globals.h"
 #include "sector.h"
 #include "lispreader.h"
 #include "badguy.h"
@@ -263,7 +265,20 @@ Sector::write(LispWriter& writer)
 {
   writer.write_string("name", name);
   writer.write_float("gravity", gravity);
+  writer.write_string("music", song_title);
 
+  // write spawnpoints
+  for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
+      ++i) {
+    SpawnPoint* spawn = *i;
+    writer.start_list("playerspawn");
+    writer.write_string("name", spawn->name);
+    writer.write_float("x", spawn->pos.x);
+    writer.write_float("y", spawn->pos.y);
+    writer.end_list("playerspawn");
+  }
+
+  // write objects
   for(GameObjects::iterator i = gameobjects.begin();
       i != gameobjects.end(); ++i) {
     Serializable* serializable = dynamic_cast<Serializable*> (*i);
@@ -273,6 +288,38 @@ Sector::write(LispWriter& writer)
 }
 
 void
+Sector::do_vertical_flip()
+{
+  for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
+    {
+    TileMap* tilemap = dynamic_cast<TileMap*> (*i);
+    if(tilemap)
+      {
+      tilemap->do_vertical_flip();
+      }
+
+    BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
+    if(badguy)
+      badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32;
+    Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
+    if(trampoline)
+      trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32;
+    FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
+    if(flying_platform)
+      flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32;
+    Door* door = dynamic_cast<Door*> (*i);
+    if(door)
+      door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y - 32);
+    }
+
+  for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
+      ++i) {
+    SpawnPoint* spawn = *i;
+    spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32;
+  }
+}
+
+void
 Sector::add_object(GameObject* object)
 {
   gameobjects_new.push_back(object);
@@ -330,6 +377,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 */) {
@@ -405,7 +458,6 @@ Sector::action(float elapsed_time)
           gameobjects.push_back(*i);
   }
   gameobjects_new.clear();
-
 }
 
 void
@@ -761,7 +813,7 @@ Sector::trygrabdistro(const Vector& pos, int bounciness)
     throw SuperTuxException(errmsg, __FILE__, __LINE__); */
     
     //Bad tiles (i.e. tiles that are not defined in supertux.stgt but appear in the map) are changed to ID 0 (blank tile)
-    std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos) << ")" << std::endl;
+    std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos).id << ")" << std::endl;
     solids->change_at(pos,0);
     tile = solids->get_tile_at(pos);
   }