Instead of setting the level to be flipped from the level file, it is now passed...
authorRicardo Cruz <rick2@aeiou.pt>
Wed, 7 Jul 2004 17:56:01 +0000 (17:56 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Wed, 7 Jul 2004 17:56:01 +0000 (17:56 +0000)
This way we can make a level designed to be played the two ways, and then the put them in the world map one after the other.
I have played the castle level flipped, and I've to say it is soo damn cool! It is like you were playing a completely different level.

It is also possible to set levels to be flipped by using --debug (this will be temporary).

SVN-Revision: 1535

src/gameloop.cpp
src/gameloop.h
src/level.cpp
src/level.h
src/sector.cpp
src/worldmap.cpp
src/worldmap.h

index 15c9505..0e7d27c 100644 (file)
@@ -59,9 +59,9 @@
 
 GameSession* GameSession::current_ = 0;
 
-GameSession::GameSession(const std::string& levelname_, int mode)
+GameSession::GameSession(const std::string& levelname_, int mode, bool flip_level_)
   : level(0), currentsector(0), st_gl_mode(mode),
-    end_sequence(NO_ENDSEQUENCE), levelname(levelname_)
+    end_sequence(NO_ENDSEQUENCE), levelname(levelname_), flip_level(flip_level_)
 {
   current_ = this;
   
@@ -74,6 +74,9 @@ GameSession::GameSession(const std::string& levelname_, int mode)
 
   context = new DrawingContext();
 
+  if(debug_mode)
+    flip_level = true;
+
   restart_level();
 }
 
@@ -100,6 +103,8 @@ GameSession::restart_level()
 
   level = new Level;
   level->load(levelname);
+  if(flip_level)
+    level->do_vertical_flip();
   currentsector = level->get_sector("main");
   if(!currentsector)
     st_abort("Level has no main sector.", "");
@@ -165,7 +170,7 @@ GameSession::levelintro(void)
       Vector(0, 400), LAYER_FOREGROUND1);
 
 
-  if(level->is_level_flipped())
+  if(flip_level)
     context.draw_text_center(white_text,
       _("Level Vertically Flipped!"),
       Vector(0, 310), LAYER_FOREGROUND1);
index 1a3ac89..196a74a 100644 (file)
@@ -72,6 +72,7 @@ private:
   bool game_pause;
 
   std::string levelname;
+  bool flip_level;
 
   // the sector and spawnpoint we shoudl spawn after this frame
   std::string newsector;
@@ -84,7 +85,7 @@ public:
   DrawingContext* context;
   Timer time_left;
 
-  GameSession(const std::string& level, int mode);
+  GameSession(const std::string& level, int mode, bool flip_level_ = false);
   ~GameSession();
 
   /** Enter the busy loop */
index a13f2f2..7b42e52 100644 (file)
@@ -61,8 +61,6 @@ Level::load(const std::string& filename)
     return;
   }
 
-  vertical_flip = false;
-
   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)));
@@ -75,8 +73,6 @@ Level::load(const std::string& filename)
       author = lisp_string(data);
     } else if(token == "time") {
       time_left = lisp_integer(data);
-    } else if(token == "flip") {
-      vertical_flip = lisp_boolean(data);
     } else if(token == "sector") {
       Sector* sector = new Sector;
       sector->parse(reader);
@@ -88,12 +84,6 @@ Level::load(const std::string& filename)
   }
   
   delete level;
-
-  if(vertical_flip)
-    {
-    for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
-      i->second->do_vertical_flip();
-    }
 }
 
 void
@@ -102,18 +92,10 @@ Level::load_old_format(LispReader& reader)
   reader.read_string("name", name);
   reader.read_string("author", author);
   reader.read_int("time", time_left);
-  vertical_flip = false;
-  reader.read_bool("flip", vertical_flip);
 
   Sector* sector = new Sector;
   sector->parse_old_format(reader);
   add_sector(sector);
-
-  if(vertical_flip)
-    {
-    for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
-      i->second->do_vertical_flip();
-    }
 }
 
 void
@@ -135,9 +117,6 @@ Level::save(const std::string& filename)
 
  for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
    {
-   if(vertical_flip)
-     i->second->do_vertical_flip();
-
    writer->start_list("sector");
    i->second->write(*writer);
    writer->end_list("sector");
@@ -156,6 +135,13 @@ Level::~Level()
 }
 
 void
+Level::do_vertical_flip()
+{
+  for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
+    i->second->do_vertical_flip();
+}
+
+void
 Level::add_sector(Sector* sector)
 {
   sectors.insert(std::make_pair(sector->get_name(), sector));       
index 7e4c335..0068fbe 100644 (file)
@@ -49,8 +49,8 @@ public:
   const std::string& get_author() const
   { return author; }
 
-  bool is_level_flipped()
-  { return vertical_flip; }
+  /** Flips the level vertically */
+  void do_vertical_flip();
 
   void add_sector(Sector* sector);
 
@@ -58,10 +58,6 @@ public:
 
 private:
   void load_old_format(LispReader& reader);
-
-  /** If true, it will flip the level vertically, during the
-      parsing process */
-  bool vertical_flip;
 };
 
 #endif /*SUPERTUX_LEVEL_H*/
index 9c7f000..4972ecc 100644 (file)
@@ -303,19 +303,19 @@ Sector::do_vertical_flip()
       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;
+      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;
+      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);
+      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;
+    spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32;
   }
 }
 
index 811274a..af1c3a9 100644 (file)
@@ -428,6 +428,8 @@ WorldMap::load_map()
                       reader.read_string("name", level.name);
                       reader.read_int("x", level.x);
                       reader.read_int("y", level.y);
+                      level.vertical_flip = false;
+                      reader.read_bool("flip", level.vertical_flip);
 
                       levels.push_back(level);
                     }
@@ -646,7 +648,7 @@ WorldMap::update(float delta)
               shrink_fade(Vector((level->x*32 + 16 + offset.x),(level->y*32 + 16
                       + offset.y)), 500);
               GameSession session(datadir +  "/levels/" + level->name,
-                                  ST_GL_LOAD_LEVEL_FILE);
+                                  ST_GL_LOAD_LEVEL_FILE, level->vertical_flip);
 
               switch (session.run())
                 {
index f4cc0f5..7a85f0f 100644 (file)
@@ -136,6 +136,9 @@ public:
     std::string title;
     bool solved;
 
+    /** Check if this level should be vertically flipped */
+    bool vertical_flip;
+
     /** Filename of the extro text to show once the level is
         successfully completed */
     std::string extro_filename;