From 8d033f0cbe51f8cf71898a6a4f2e77dcc32e3857 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Tue, 27 Apr 2004 15:15:18 +0000 Subject: [PATCH] - added extro support to worldmap, crashes however, no idea why: 0x080826f5 in display_text_file(std::string const&, Surface*) () at music_manager.cpp:26 26 MusicManager::MusicManager() (gdb) where #0 0x080826f5 in display_text_file(std::string const&, Surface*) () at music_manager.cpp:26 #1 0x080826b5 in display_text_file(std::string const&, std::string const&) (file=@0x88ad5d0, surface=@0xbffff230) at text.cpp:234 #2 0x08093b31 in WorldMapNS::WorldMap::update() (this=0xbffff3b0) at worldmap.cpp:685 SVN-Revision: 782 --- src/gameloop.cpp | 4 ++-- src/level.cpp | 14 ++++---------- src/text.cpp | 10 +++++----- src/text.h | 5 +++-- src/worldmap.cpp | 8 ++++++++ src/worldmap.h | 4 ++++ 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index a51a5fa33..b5857c902 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -413,9 +413,9 @@ GameSession::check_end_conditions() Player* tux = world->get_tux(); /* End of level? */ - int endpos = (World::current()->get_level()->width-10) * 32; + int endpos = (World::current()->get_level()->width-5) * 32; Tile* endtile = collision_goal(tux->base); - //printf("EndTile: %p.\n", endtile); + // fallback in case the other endpositions don't trigger if (tux->base.x >= endpos || (endtile && endtile->data >= 1) || (end_sequence && !endsequence_timer.check())) diff --git a/src/level.cpp b/src/level.cpp index 8ab407891..9a127403f 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -282,22 +282,17 @@ Level::load(const std::string& subset, int level) int Level::load(const std::string& filename) { - FILE * fi; - lisp_object_t* root_obj = 0; - fi = fopen(filename.c_str(), "r"); - if (fi == NULL) + lisp_object_t* root_obj = lisp_read_from_file(filename); + if (!root_obj) { - perror(filename.c_str()); + std::cout << "Level: Couldn't load file: " << filename << std::endl; return -1; } - lisp_stream_t stream; - lisp_stream_init_file (&stream, fi); - root_obj = lisp_read (&stream); - if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) { printf("World: Parse Error in file %s", filename.c_str()); + return -1; } vector ia_tm; @@ -510,7 +505,6 @@ Level::load(const std::string& filename) } lisp_free(root_obj); - fclose(fi); return 0; } diff --git a/src/text.cpp b/src/text.cpp index 4d952ff46..6560327f4 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -228,14 +228,14 @@ Text::erasecenteredtext(const char * text, int y, Surface * ptexture, int updat #define SCROLL 60 #define ITEMS_SPACE 4 -void display_text_file(char *file, char* surface) +void display_text_file(const std::string& file, const std::string& surface) { -Surface* sur = new Surface(datadir + surface, IGNORE_ALPHA); -display_text_file(file, sur); -delete sur; + Surface* sur = new Surface(datadir + surface, IGNORE_ALPHA); + display_text_file(file, sur); + delete sur; } -void display_text_file(char *file, Surface* surface) +void display_text_file(const std::string& file, Surface* surface) { int done; int scroll, speed; diff --git a/src/text.h b/src/text.h index 6a02999b2..d82a25681 100644 --- a/src/text.h +++ b/src/text.h @@ -21,10 +21,11 @@ #ifndef SUPERTUX_TEXT_H #define SUPERTUX_TEXT_H +#include #include "texture.h" -void display_text_file(char *file, char* surface); -void display_text_file(char *file, Surface* surface); +void display_text_file(const std::string& file, const std::string& surface); +void display_text_file(const std::string& file, Surface* surface); /* Kinds of texts. */ enum { diff --git a/src/worldmap.cpp b/src/worldmap.cpp index d5538d9ad..626644f78 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -420,6 +420,7 @@ WorldMap::load_map() level.south = true; level.west = true; + reader.read_string("extro-filename", &level.extro_filename); reader.read_string("name", &level.name); reader.read_int("x", &level.x); reader.read_int("y", &level.y); @@ -678,6 +679,13 @@ WorldMap::update() std::cout << "Walk to dir: " << dir << std::endl; } + + if (!level->extro_filename.empty()) + { // Display final credits and go back to the main menu + display_text_file(level->extro_filename, + "/images/background/arctis2.jpg"); + quit = true; + } } break; diff --git a/src/worldmap.h b/src/worldmap.h index c2a7154a8..8990dcf7a 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -153,6 +153,10 @@ public: std::string title; bool solved; + /** Filename of the extro text to show once the level is + successfully completed */ + std::string extro_filename; + // Directions which are walkable from this level bool north; bool east; -- 2.11.0