Menu* worldmap_menu = 0;
+static const float TUXSPEED = 200;
+
namespace WorldMapNS {
Direction reverse_dir(Direction direction)
}
else
{
- // Let tux walk a few pixels (20 pixel/sec)
- offset += 20.0f * delta;
+ // Let tux walk
+ offset += TUXSPEED * delta;
if (offset > 32)
{ // We reached the next tile, so we check what to do now
name = "<no title>";
music = "salcon.mod";
+ intro_displayed = false;
total_stats.reset();
}
void
WorldMap::load_map()
{
+ levels_path = FileSystem::dirname(map_filename);
+
try {
lisp::Parser parser;
- std::string filename
- = get_resource_filename("/levels/worldmap/" + map_filename);
+ std::string filename = get_resource_filename(map_filename);
std::auto_ptr<lisp::Lisp> root (parser.parse(filename));
const lisp::Lisp* lisp = root->get_lisp("supertux-worldmap");
if(!lisp)
throw new std::runtime_error("file isn't a supertux-worldmap file.");
- lisp::ListIterator iter(lisp->get_cdr());
+ lisp::ListIterator iter(lisp);
while(iter.next()) {
if(iter.item() == "tilemap") {
if(tilemap.size() > 0)
const lisp::Lisp* props = iter.lisp();
props->get("name", name);
props->get("music", music);
+ props->get("intro-filename", intro_filename);
props->get("start_pos_x", start_x);
props->get("start_pos_y", start_y);
} else if(iter.item() == "special-tiles") {
try {
lisp::Parser parser;
std::auto_ptr<lisp::Lisp> root (
- parser.parse(get_resource_filename("levels/" + level.name)));
+ parser.parse(get_resource_filename(levels_path + level.name)));
const lisp::Lisp* level_lisp = root->get_lisp("supertux-level");
if(!level_lisp)
// do a shriking fade to the level
shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),
(level->pos.y*32 + 16 + offset.y)), 500);
- GameSession session(
- get_resource_filename(std::string("levels/" + level->name)),
+ GameSession session(get_resource_filename(levels_path + level->name),
ST_GL_LOAD_LEVEL_FILE, &level->statistics);
switch (session.run())
}
/* 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)
- {
- if (!level->extro_filename.empty())
- {
+ if(level_finished) {
+ if (!level->extro_filename.empty()) {
// Display a text file
- display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE,
- white_big_text , white_text, white_small_text, blue_text );
- }
+ std::string filename = levels_path + level->extro_filename;
+ display_text_file(filename, SCROLL_SPEED_MESSAGE,
+ white_big_text , white_text, white_small_text, blue_text );
+ }
if (!level->next_worldmap.empty())
{
song = SoundManager::get()->load_music(datadir + "/music/" + music);
SoundManager::get()->play_music(song);
- FrameRate frame_rate(10);
- frame_rate.set_frame_limit(false);
-
- frame_rate.start();
+ if(!intro_displayed && intro_filename != "") {
+ std::string filename = levels_path + intro_filename;
+ display_text_file(filename, SCROLL_SPEED_MESSAGE,
+ white_big_text, white_text, white_small_text, blue_text);
+ intro_displayed = true;
+ }
+ Uint32 lastticks = SDL_GetTicks();
DrawingContext context;
- while(!quit)
- {
- float delta = frame_rate.get();
-
- delta *= 1.3f;
-
- if (delta > 10.0f)
- delta = .3f;
-
- frame_rate.update();
-
- Vector tux_pos = tux->get_pos();
- if (1)
- {
- offset.x = -tux_pos.x + screen->w/2;
- offset.y = -tux_pos.y + screen->h/2;
-
- if (offset.x > 0) offset.x = 0;
- if (offset.y > 0) offset.y = 0;
+ while(!quit) {
+ Uint32 ticks = SDL_GetTicks();
+ float elapsed_time = float(ticks - lastticks) / 1000;
+ global_time += elapsed_time;
+ lastticks = ticks;
+
+ // 40 fps minimum
+ if(elapsed_time > .025)
+ elapsed_time = .025;
+
+ Vector tux_pos = tux->get_pos();
+
+ offset.x = -tux_pos.x + screen->w/2;
+ offset.y = -tux_pos.y + screen->h/2;
- if (offset.x < screen->w - width*32) offset.x = screen->w - width*32;
- if (offset.y < screen->h - height*32) offset.y = screen->h - height*32;
- }
+ if (offset.x > 0) offset.x = 0;
+ if (offset.y > 0) offset.y = 0;
- draw(context, offset);
- get_input();
- update(delta);
+ if (offset.x < screen->w - width*32) offset.x = screen->w - width*32;
+ if (offset.y < screen->h - height*32) offset.y = screen->h - height*32;
+
+ draw(context, offset);
+ get_input();
+ update(elapsed_time);
- if(Menu::current())
- {
- Menu::current()->draw(context);
- mouse_cursor->draw(context);
- }
-
- context.do_drawing();
-
- SDL_Delay(20);
+ if(Menu::current()) {
+ Menu::current()->draw(context);
+ mouse_cursor->draw(context);
}
+
+ context.do_drawing();
+ }
}
void
writer.write_string("title",
std::string(name + " - " + nb_solved_levels_str+"/"+total_levels_str));
writer.write_string("map", map_filename);
+ writer.write_bool("intro-displayed", intro_displayed);
writer.write_int("lives", player_status.lives);
writer.write_int("distros", player_status.lives);
writer.write_int("max-score-multiplier", player_status.max_score_multiplier);
savegame->get("map", map_filename);
load_map();
+ savegame->get("intro-displayed", intro_displayed);
savegame->get("lives", player_status.lives);
savegame->get("distros", player_status.distros);
savegame->get("max-score-multiplier", player_status.max_score_multiplier);
}
} // namespace WorldMapNS
-
-/* Local Variables: */
-/* mode:c++ */
-/* End: */
-