[Super-tux-commit] supertux/src badguy.h,1.57,1.58 gameloop.cpp,1.153,1.154 interactive_object.h,1.2
Brought to you by:
wkendrick
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11947/src Modified Files: badguy.h gameloop.cpp interactive_object.h level.cpp level.h sector.cpp sector.h tilemap.cpp tilemap.h Log Message: Added vertical flipping to levels! To enable it, add to the level file (flip #t) . Index: sector.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- sector.h 28 Jun 2004 11:30:27 -0000 1.6 +++ sector.h 7 Jul 2004 11:39:35 -0000 1.7 @@ -112,6 +112,10 @@ the tile which the badguy is walking on an killing him this way */ void trybumpbadguy(const Vector& pos); + /** Flip the all the sector vertically. The purpose of this is to let + player to play the same level in a different way :) */ + void do_vertical_flip(); + /** @evil@ */ static Sector* current() { return _current; } Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- sector.cpp 2 Jul 2004 15:12:48 -0000 1.14 +++ sector.cpp 7 Jul 2004 11:39:35 -0000 1.15 @@ -288,6 +288,38 @@ } 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; + FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i); + if(flying_platform) + flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y; + Door* door = dynamic_cast<Door*> (*i); + if(door) + door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y); + } + + for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); + ++i) { + SpawnPoint* spawn = *i; + spawn->pos.y = solids->get_height()*32 - spawn->pos.y; + } +} + +void Sector::add_object(GameObject* object) { gameobjects_new.push_back(object); Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- level.h 16 Jun 2004 00:40:42 -0000 1.59 +++ level.h 7 Jul 2004 11:39:35 -0000 1.60 @@ -49,12 +49,19 @@ const std::string& get_author() const { return author; } + bool is_level_flipped() + { return vertical_flip; } + void add_sector(Sector* sector); Sector* get_sector(const std::string& name); 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: badguy.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.h,v retrieving revision 1.57 retrieving revision 1.58 diff -u -d -r1.57 -r1.58 --- badguy.h 1 Jul 2004 13:39:25 -0000 1.57 +++ badguy.h 7 Jul 2004 11:39:35 -0000 1.58 @@ -99,6 +99,7 @@ bool stay_on_platform; Direction dir; + Vector start_position; Timer frozen_timer; // gets frozen when a ice shot hits it @@ -108,7 +109,6 @@ int squishcount; /// number of times this enemy was squiched Vector target; // Target that badguy is aiming for (wingling uses this) Timer timer; - Vector start_position; Physic physic; float angle; Index: interactive_object.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/interactive_object.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- interactive_object.h 9 Jun 2004 05:23:20 -0000 1.2 +++ interactive_object.h 7 Jul 2004 11:39:35 -0000 1.3 @@ -43,6 +43,9 @@ const base_type& get_area() const { return area; } + void set_area(float x, float y) + { area.x = x; area.y = y; } + protected: base_type area; }; Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- level.cpp 29 Jun 2004 13:00:41 -0000 1.95 +++ level.cpp 7 Jul 2004 11:39:35 -0000 1.96 @@ -44,6 +44,7 @@ Level::Level() : name("noname"), author("mr. x"), time_left(500) + { } @@ -60,6 +61,8 @@ 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))); @@ -72,6 +75,8 @@ 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); @@ -83,6 +88,12 @@ } delete level; + + if(vertical_flip) + { + for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) + i->second->do_vertical_flip(); + } } void @@ -91,10 +102,18 @@ 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 @@ -116,6 +135,9 @@ 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"); Index: tilemap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tilemap.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- tilemap.cpp 2 Jul 2004 15:14:48 -0000 1.15 +++ tilemap.cpp 7 Jul 2004 11:39:35 -0000 1.16 @@ -33,13 +33,13 @@ #include "lispwriter.h" TileMap::TileMap() - : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES) + : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false) { tilemanager = TileManager::instance(); } TileMap::TileMap(LispReader& reader) - : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES) + : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false) { tilemanager = TileManager::instance(); @@ -84,7 +84,7 @@ } TileMap::TileMap(int layer_, bool solid_, size_t width_, size_t height_) - : solid(solid_), speed(1), width(width_), height(height_), layer(layer_) + : solid(solid_), speed(1), width(width_), height(height_), layer(layer_), vertical_flip(false) { } @@ -131,9 +131,15 @@ void TileMap::draw(DrawingContext& context) -{ +{ if (speed == 1.0) { + if(vertical_flip) // flip vertically the tiles, in case we are playing this + { // level upside down + context.push_transform(); + context.set_drawing_effect(VERTICAL_FLIP); + } + /** if we don't round here, we'll have a 1 pixel gap on screen sometimes. * I have no idea why */ float start_x = roundf(context.get_translation().x); @@ -153,6 +159,9 @@ tilemanager->draw_tile(context, tiles[ty*width + tx].id, pos, layer); } } + + if(vertical_flip) // disable flipping, if applied + context.pop_transform(); } else { @@ -161,6 +170,8 @@ context.push_transform(); context.set_translation(Vector(trans_x * speed, trans_y * speed)); + if(vertical_flip) + context.set_drawing_effect(VERTICAL_FLIP); float start_x = roundf(context.get_translation().x); float start_y = roundf(context.get_translation().y); @@ -235,6 +246,19 @@ width = new_width; } +void +TileMap::do_vertical_flip() +{ + // remap tiles vertically flipped + for(int y = 0; y < height / 2; ++y) { + for(int x = 0; x < width; ++x) { + std::swap(tiles[y*width + x], tiles[(((height-1)*width) - (y*width)) + x]); + } + } + + vertical_flip = true; +} + Tile* TileMap::get_tile(int x, int y) const { Index: tilemap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tilemap.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- tilemap.h 2 Jul 2004 15:14:48 -0000 1.10 +++ tilemap.h 7 Jul 2004 11:39:35 -0000 1.11 @@ -64,6 +64,10 @@ */ void resize(int newwidth, int newheight); + /** Flip the all tile map vertically. The purpose of this is to let + player to play the same level in a different way :) */ + void do_vertical_flip(); + size_t get_width() const { return width; } @@ -96,6 +100,8 @@ float speed; int width, height; int layer; + + bool vertical_flip; }; #endif /*SUPERTUX_TILEMAP_H*/ Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.153 retrieving revision 1.154 diff -u -d -r1.153 -r1.154 --- gameloop.cpp 22 Jun 2004 12:20:22 -0000 1.153 +++ gameloop.cpp 7 Jul 2004 11:39:35 -0000 1.154 @@ -164,6 +164,12 @@ std::string(_("by ")) + level->get_author(), Vector(0, 400), LAYER_FOREGROUND1); + + if(level->is_level_flipped()) + context.draw_text_center(white_text, + _("Level Vertically Flipped!"), + Vector(0, 310), LAYER_FOREGROUND1); + context.do_drawing(); SDL_Event event; @@ -763,7 +769,7 @@ { sprintf(str, "%2.1f", fps_fps); context.draw_text(white_text, "FPS", - Vector(screen->w - white_text->get_text_width("FPS "), 40), + Vector(screen->w - white_text->get_text_width("FPS "), 40), LAYER_FOREGROUND1); context.draw_text(gold_text, str, Vector(screen->w-4*16, 40), LAYER_FOREGROUND1); |