#include "worldmap.h"
#include "resources.h"
#include "misc.h"
-#include "scene.h"
+#include "player_status.h"
#define map_message_TIME 2.8
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()
{
- std::string::size_type p = map_filename.find_last_of('/');
- if(p == std::string::npos)
- levels_path = "";
- else
- levels_path = map_filename.substr(0, p+1);
+ levels_path = FileSystem::dirname(map_filename);
try {
lisp::Parser parser;
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") {
}
/* 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
if(filename == "")
return;
- std::cout << "savegame: " << filename << std::endl;
-
std::ofstream file(filename.c_str(), std::ios::out);
lisp::Writer writer(file);
writer.write_string("title",
std::string(name + " - " + nb_solved_levels_str+"/"+total_levels_str));
writer.write_string("map", map_filename);
- 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);
+ writer.write_bool("intro-displayed", intro_displayed);
writer.start_list("tux");
writer.write_float("x", tux->get_tile_pos().x);
writer.write_float("y", tux->get_tile_pos().y);
writer.write_string("back", direction_to_string(tux->back_direction));
- writer.write_string("bonus", bonus_to_string(player_status.bonus));
+ player_status.write(writer);
+ writer.write_string("back", direction_to_string(tux->back_direction));
writer.end_list("tux");
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);
if (player_status.lives < 0)
- player_status.lives = START_LIVES;
+ player_status.reset();
const lisp::Lisp* tux_lisp = savegame->get_lisp("tux");
if(tux)
{
Vector p;
std::string back_str = "none";
- std::string bonus_str = "none";
tux_lisp->get("x", p.x);
tux_lisp->get("y", p.y);
tux_lisp->get("back", back_str);
- tux_lisp->get("bonus", bonus_str);
+ player_status.read(*tux_lisp);
- player_status.bonus = string_to_bonus(bonus_str);
tux->back_direction = string_to_direction(back_str);
tux->set_tile_pos(p);
}
}
} // namespace WorldMapNS
-
-/* Local Variables: */
-/* mode:c++ */
-/* End: */
-