[Super-tux-commit] supertux/src worldmap.cpp,1.95,1.96 worldmap.h,1.36,1.37
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-07-16 19:22:34
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16643/src Modified Files: worldmap.cpp worldmap.h Log Message: Implemented a new special-tile field that should replaced the depricated level field in world maps. Also extended display_text_file(). special-tile can have the following flags: [integer] x / y - necessary to say where the tile is located [string] extro-filename - read the given file * [integer] swap-x / swap-y - say coordinates for swapping * [string] map-message - show a message in the world map viewer [string] goto-world - change the world to the given one * [boolean] flip-level - flip vertically the level (of course, only works when there is a level) [boolean] exit-game - quit game * [string] level - feed a level to this tile * - if there is a level, open it only if the level is successful Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.95 retrieving revision 1.96 diff -u -d -r1.95 -r1.96 --- worldmap.cpp 10 Jul 2004 14:22:59 -0000 1.95 +++ worldmap.cpp 16 Jul 2004 19:22:26 -0000 1.96 @@ -415,8 +415,8 @@ while(!lisp_nil_p(cur)) { lisp_object_t* element = lisp_car(cur); - - if (strcmp(lisp_symbol(lisp_car(element)), "level") == 0) + + if (strcmp(lisp_symbol(lisp_car(element)), "special-tile") == 0) { Level level; LispReader reader(lisp_cdr(element)); @@ -428,11 +428,42 @@ level.west = true; reader.read_string("extro-filename", level.extro_filename); + reader.read_string("map-message", level.display_map_message); + reader.read_string("goto-world", level.goto_worldmap); + reader.read_string("level", level.name, true); + reader.read_int("x", level.x); + reader.read_int("y", level.y); + level.swap_x = level.swap_y = -1; + reader.read_int("swap-x", level.swap_x); + reader.read_int("swap-y", level.swap_y); + level.vertical_flip = false; + reader.read_bool("flip-level", level.vertical_flip); + level.quit_worldmap = false; + reader.read_bool("exit-game", level.quit_worldmap); + + levels.push_back(level); + } + + /* Kept for backward compability */ + else if (strcmp(lisp_symbol(lisp_car(element)), "level") == 0) + { + Level level; + LispReader reader(lisp_cdr(element)); + level.solved = false; + + level.north = true; + level.east = true; + level.south = true; + level.west = true; + + reader.read_string("extro-filename", level.extro_filename); + if(!level.extro_filename.empty()) + level.quit_worldmap = true; reader.read_string("name", level.name, true); reader.read_int("x", level.x); reader.read_int("y", level.y); level.vertical_flip = false; - reader.read_bool("flip", level.vertical_flip); + level.swap_x = level.swap_y = -1; levels.push_back(level); } @@ -639,8 +670,17 @@ { if (enter_level && !tux->is_moving()) { + bool level_finished = true; Level* level = at_level(); - if (level) + if (!level) + { + std::cout << "Nothing to enter at: " + << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl; + return; + } + + + if(!level->name.empty()) { if (level->x == tux->get_tile_pos().x && level->y == tux->get_tile_pos().y) @@ -658,6 +698,7 @@ { case GameSession::ES_LEVEL_FINISHED: { + level_finished = true; bool old_level_state = level->solved; level->solved = true; @@ -693,30 +734,22 @@ std::cout << "Walk to dir: " << dir << std::endl; } - - if (!level->extro_filename.empty()) - { - MusicRef theme = - sound_manager->load_music(datadir + "/music/theme.mod"); - sound_manager->play_music(theme); - // Display final credits and go back to the main menu - display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE); - display_text_file("CREDITS", SCROLL_SPEED_CREDITS); - quit = true; - } } break; case GameSession::ES_LEVEL_ABORT: + level_finished = false; /* In case the player's abort the level, keep it using the old status. But the minimum lives and no bonus. */ player_status.score = old_player_status.score; player_status.distros = old_player_status.distros; player_status.lives = std::min(old_player_status.lives, player_status.lives); player_status.bonus = player_status.NO_BONUS; + break; case GameSession::ES_GAME_OVER: - { + { + level_finished = false; /* draw an end screen */ /* in the future, this should make a dialog a la SuperMario, asking if the player wants to restart the world map with no score and from @@ -724,7 +757,7 @@ char str[80]; DrawingContext context; - context.draw_gradient(Color (0, 255, 0), Color (255, 0, 255), + context.draw_gradient(Color (200,240,220), Color(200,200,220), LAYER_BACKGROUND0); context.draw_text_center(blue_text, _("GAMEOVER"), @@ -732,7 +765,7 @@ sprintf(str, _("SCORE: %d"), player_status.score); context.draw_text_center(gold_text, str, - Vector(0, 224), LAYER_FOREGROUND1); + Vector(0, 230), LAYER_FOREGROUND1); sprintf(str, _("COINS: %d"), player_status.distros); context.draw_text_center(gold_text, str, @@ -746,7 +779,7 @@ quit = true; player_status.reset(); break; - } + } case GameSession::ES_NONE: assert(false); // Should never be reached @@ -757,13 +790,29 @@ Menu::set_current(0); if (!savegame_file.empty()) savegame(savegame_file); - return; } } - else + /* The porpose of the next checking is that if the player lost + the level (in case there is one), don't show anything */ + if(level_finished) { - std::cout << "Nothing to enter at: " - << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl; + if (!level->extro_filename.empty()) + { + // Display a text file + display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE); + } + if (level->swap_x != -1 && level->swap_y != -1) + { + // TODO: add an effect, like a camera scrolling, or at least, a fading + tux->set_tile_pos(Vector(level->swap_x, level->swap_y)); + } + if (!level->goto_worldmap.empty()) + { + // Load given worldmap + loadmap(level->goto_worldmap); + } + if (level->quit_worldmap) + quit = true; } } else @@ -835,6 +884,9 @@ for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) { + if(i->name.empty()) + continue; + if (i->solved) context.draw_surface(leveldot_green, Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1); @@ -889,13 +941,21 @@ if (i->x == tux->get_tile_pos().x && i->y == tux->get_tile_pos().y) { - if(i->title == "") - get_level_title(*i); + if(!i->name.empty()) + { + if(i->title == "") + get_level_title(*i); - context.draw_text(white_text, i->title, - Vector(screen->w/2 - white_text->get_text_width(i->title)/2, - screen->h - white_text->get_height() - 30), - LAYER_FOREGROUND1); + context.draw_text_center(white_text, i->title, + Vector(0, screen->h - white_text->get_height() - 30), + LAYER_FOREGROUND1); + } + + /* Display a message in the map, if any as been selected */ + if(!i->display_map_message.empty()) + context.draw_text_center(gold_text, i->display_map_message, + Vector(0, screen->h - white_text->get_height() - 60), + LAYER_FOREGROUND1); break; } } Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- worldmap.h 10 Jul 2004 10:59:00 -0000 1.36 +++ worldmap.h 16 Jul 2004 19:22:26 -0000 1.37 @@ -139,6 +139,8 @@ std::string title; bool solved; + /** Optional flags: */ + /** Check if this level should be vertically flipped */ bool vertical_flip; @@ -146,6 +148,18 @@ successfully completed */ std::string extro_filename; + /** Position to swap player */ + int swap_x, swap_y; + + /** Message to show in the Map */ + std::string display_map_message; + + /** Go to this world */ + std::string goto_worldmap; + + /** Quit the worldmap */ + bool quit_worldmap; + // Directions which are walkable from this level bool north; bool east; |