From 576d79481d0cec9dd441b9b235a01da63584d137 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Wed, 7 Jul 2004 17:56:01 +0000 Subject: [PATCH] Instead of setting the level to be flipped from the level file, it is now passed through the world. 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 | 11 ++++++++--- src/gameloop.h | 3 ++- src/level.cpp | 28 +++++++--------------------- src/level.h | 8 ++------ src/sector.cpp | 8 ++++---- src/worldmap.cpp | 4 +++- src/worldmap.h | 3 +++ 7 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 15c950528..0e7d27c48 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -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); diff --git a/src/gameloop.h b/src/gameloop.h index 1a3ac89ac..196a74a3b 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -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 */ diff --git a/src/level.cpp b/src/level.cpp index a13f2f26c..7b42e5287 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -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)); diff --git a/src/level.h b/src/level.h index 7e4c3354c..0068fbe1d 100644 --- a/src/level.h +++ b/src/level.h @@ -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*/ diff --git a/src/sector.cpp b/src/sector.cpp index 9c7f000e4..4972ecc0d 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -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 (*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 (*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 (*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; } } diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 811274af1..af1c3a9ad 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -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()) { diff --git a/src/worldmap.h b/src/worldmap.h index f4cc0f585..7a85f0fab 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -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; -- 2.11.0