#include <fstream>
#include <vector>
#include <assert.h>
+#include <unistd.h>
#include "globals.h"
-#include "texture.h"
-#include "screen.h"
+#include "screen/texture.h"
+#include "screen/screen.h"
+#include "screen/drawing_context.h"
#include "lispreader.h"
#include "gameloop.h"
#include "setup.h"
#include "worldmap.h"
+#include "resources.h"
namespace WorldMapNS {
{
switch(direction)
{
- case WEST:
- return EAST;
- case EAST:
- return WEST;
- case NORTH:
- return SOUTH;
- case SOUTH:
- return NORTH;
- case NONE:
- return NONE;
+ case D_WEST:
+ return D_EAST;
+ case D_EAST:
+ return D_WEST;
+ case D_NORTH:
+ return D_SOUTH;
+ case D_SOUTH:
+ return D_NORTH;
+ case D_NONE:
+ return D_NONE;
}
- return NONE;
+ return D_NONE;
}
std::string
{
switch(direction)
{
- case WEST:
+ case D_WEST:
return "west";
- case EAST:
+ case D_EAST:
return "east";
- case NORTH:
+ case D_NORTH:
return "north";
- case SOUTH:
+ case D_SOUTH:
return "south";
default:
return "none";
string_to_direction(const std::string& directory)
{
if (directory == "west")
- return WEST;
+ return D_WEST;
else if (directory == "east")
- return EAST;
+ return D_EAST;
else if (directory == "north")
- return NORTH;
+ return D_NORTH;
else if (directory == "south")
- return SOUTH;
+ return D_SOUTH;
else
- return NONE;
+ return D_NONE;
}
-TileManager* TileManager::instance_ = 0;
-
TileManager::TileManager()
{
- std::string stwt_filename = datadir + "images/worldmap/antarctica.stwt";
+ std::string stwt_filename = datadir + "/images/worldmap/antarctica.stwt";
lisp_object_t* root_obj = lisp_read_from_file(stwt_filename);
if (!root_obj)
tile->south = true;
tile->west = true;
tile->stop = true;
+ tile->auto_walk = false;
LispReader reader(lisp_cdr(element));
reader.read_int("id", &id);
reader.read_bool("west", &tile->west);
reader.read_bool("east", &tile->east);
reader.read_bool("stop", &tile->stop);
+ reader.read_bool("auto-walk", &tile->auto_walk);
reader.read_string("image", &filename);
tile->sprite = new Surface(
{
assert(0);
}
+
+ lisp_free(root_obj);
+}
+
+TileManager::~TileManager()
+{
+ for(std::vector<Tile*>::iterator i = tiles.begin(); i != tiles.end(); ++i)
+ delete *i;
}
Tile*
return tiles[i];
}
+//---------------------------------------------------------------------------
+
Tux::Tux(WorldMap* worldmap_)
: worldmap(worldmap_)
{
- sprite = new Surface(datadir + "/images/worldmap/tux.png", USE_ALPHA);
+ largetux_sprite = new Surface(datadir + "/images/worldmap/tux.png", USE_ALPHA);
+ firetux_sprite = new Surface(datadir + "/images/worldmap/firetux.png", USE_ALPHA);
+ smalltux_sprite = new Surface(datadir + "/images/worldmap/smalltux.png", USE_ALPHA);
+
offset = 0;
moving = false;
- tile_pos.x = 5;
+ tile_pos.x = 4;
tile_pos.y = 5;
- direction = NONE;
- input_direction = NONE;
+ direction = D_NONE;
+ input_direction = D_NONE;
+}
+
+Tux::~Tux()
+{
+ delete smalltux_sprite;
+ delete firetux_sprite;
+ delete largetux_sprite;
}
void
-Tux::draw(const Point& offset)
+Tux::draw(DrawingContext& context, const Vector& offset)
{
- Point pos = get_pos();
- sprite->draw(pos.x + offset.x,
- pos.y + offset.y);
+ Vector pos = get_pos();
+ switch (player_status.bonus)
+ {
+ case PlayerStatus::GROWUP_BONUS:
+ context.draw_surface(largetux_sprite,
+ Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS);
+ break;
+ case PlayerStatus::FLOWER_BONUS:
+ context.draw_surface(firetux_sprite,
+ Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS);
+ break;
+ case PlayerStatus::NO_BONUS:
+ context.draw_surface(smalltux_sprite,
+ Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS);
+ break;
+ }
}
-Point
+Vector
Tux::get_pos()
{
float x = tile_pos.x * 32;
switch(direction)
{
- case WEST:
+ case D_WEST:
x -= offset - 32;
break;
- case EAST:
+ case D_EAST:
x += offset - 32;
break;
- case NORTH:
+ case D_NORTH:
y -= offset - 32;
break;
- case SOUTH:
+ case D_SOUTH:
y += offset - 32;
break;
- case NONE:
+ case D_NONE:
break;
}
- return Point((int)x, (int)y);
+ return Vector((int)x, (int)y);
}
void
Tux::stop()
{
offset = 0;
- direction = NONE;
+ direction = D_NONE;
moving = false;
}
void
-Tux::update(float delta)
+Tux::action(float delta)
{
if (!moving)
{
- if (input_direction != NONE)
+ if (input_direction != D_NONE)
{
WorldMap::Level* level = worldmap->at_level();
// We got a new direction, so lets start walking when possible
- Point next_tile;
+ Vector next_tile;
if ((!level || level->solved)
&& worldmap->path_ok(input_direction, tile_pos, &next_tile))
{
}
else
{
+ if (worldmap->at(tile_pos)->auto_walk)
+ { // Turn to a new direction
+ Tile* tile = worldmap->at(tile_pos);
+ Direction dir = D_NONE;
+
+ if (tile->north && back_direction != D_NORTH)
+ dir = D_NORTH;
+ else if (tile->south && back_direction != D_SOUTH)
+ dir = D_SOUTH;
+ else if (tile->east && back_direction != D_EAST)
+ dir = D_EAST;
+ else if (tile->west && back_direction != D_WEST)
+ dir = D_WEST;
+
+ if (dir != D_NONE)
+ {
+ direction = dir;
+ back_direction = reverse_dir(direction);
+ }
+ else
+ {
+ // Should never be reached if tiledata is good
+ stop();
+ return;
+ }
+ }
+
// Walk automatically to the next tile
- Point next_tile;
+ Vector next_tile;
if (worldmap->path_ok(direction, tile_pos, &next_tile))
{
tile_pos = next_tile;
}
}
+//---------------------------------------------------------------------------
+Tile::Tile()
+{
+}
+
+Tile::~Tile()
+{
+ delete sprite;
+}
+
+//---------------------------------------------------------------------------
+
WorldMap::WorldMap()
{
+ tile_manager = new TileManager();
tux = new Tux(this);
width = 20;
leveldot_green = new Surface(datadir + "/images/worldmap/leveldot_green.png", USE_ALPHA);
leveldot_red = new Surface(datadir + "/images/worldmap/leveldot_red.png", USE_ALPHA);
- input_direction = NONE;
+ input_direction = D_NONE;
enter_level = false;
- name = "<no name>";
+ name = "<no file>";
music = "SALCON.MOD";
- song = 0;
load_map();
}
WorldMap::~WorldMap()
{
delete tux;
+ delete tile_manager;
+
+ delete level_sprite;
+ delete leveldot_green;
+ delete leveldot_red;
}
void
WorldMap::load_map()
{
- std::string filename = datadir + "levels/default/worldmap.stwm";
+ std::string filename = datadir + "/levels/default/worldmap.stwm";
lisp_object_t* root_obj = lisp_read_from_file(filename);
if (!root_obj)
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);
+
levels.push_back(level);
}
cur = lisp_cdr(cur);
}
}
+
+ lisp_free(root_obj);
+}
+
+void WorldMap::get_level_title(Level& level)
+{
+ /** get level's title */
+ level.title = "<no title>";
+
+ FILE * fi;
+ lisp_object_t* root_obj = 0;
+ fi = fopen((datadir + "/levels/" + level.name).c_str(), "r");
+ if (fi == NULL)
+ {
+ perror((datadir + "/levels/" + level.name).c_str());
+ return;
+ }
+
+ 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", level.name.c_str());
+ }
+
+ if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
+ {
+ LispReader reader(lisp_cdr(root_obj));
+ reader.read_string("name", &level.title);
+ }
+
+ lisp_free(root_obj);
+
+ fclose(fi);
+}
+
+void
+WorldMap::on_escape_press()
+{
+ // Show or hide the menu
+ if(!Menu::current())
+ Menu::set_current(worldmap_menu);
+ else
+ Menu::set_current(0);
}
void
WorldMap::get_input()
{
enter_level = false;
- input_direction = NONE;
+ input_direction = D_NONE;
SDL_Event event;
while (SDL_PollEvent(&event))
{
- if(!show_menu && event.key.keysym.sym == SDLK_ESCAPE)
- Menu::set_current(worldmap_menu);
-
- current_menu->event(event);
- if(!show_menu)
+ if (Menu::current())
+ {
+ Menu::current()->event(event);
+ }
+ else
{
switch(event.type)
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
+ case SDLK_ESCAPE:
+ on_escape_press();
+ break;
case SDLK_LCTRL:
case SDLK_RETURN:
enter_level = true;
break;
case SDL_JOYAXISMOTION:
- switch(event.jaxis.axis)
+ if (event.jaxis.axis == joystick_keymap.x_axis)
{
- case JOY_X:
- if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
- input_direction = WEST;
- else if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
- input_direction = EAST;
- break;
- case JOY_Y:
- if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
- input_direction = SOUTH;
- else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
- input_direction = NORTH;
- break;
+ if (event.jaxis.value < -joystick_keymap.dead_zone)
+ input_direction = D_WEST;
+ else if (event.jaxis.value > joystick_keymap.dead_zone)
+ input_direction = D_EAST;
+ }
+ else if (event.jaxis.axis == joystick_keymap.y_axis)
+ {
+ if (event.jaxis.value > joystick_keymap.dead_zone)
+ input_direction = D_SOUTH;
+ else if (event.jaxis.value < -joystick_keymap.dead_zone)
+ input_direction = D_NORTH;
}
break;
case SDL_JOYBUTTONDOWN:
- if (event.jbutton.button == JOY_B)
+ if (event.jbutton.button == joystick_keymap.b_button)
enter_level = true;
+ else if (event.jbutton.button == joystick_keymap.start_button)
+ on_escape_press();
break;
default:
}
}
- if (!show_menu)
+ if (!Menu::current())
{
Uint8 *keystate = SDL_GetKeyState(NULL);
if (keystate[SDLK_LEFT])
- input_direction = WEST;
+ input_direction = D_WEST;
else if (keystate[SDLK_RIGHT])
- input_direction = EAST;
+ input_direction = D_EAST;
else if (keystate[SDLK_UP])
- input_direction = NORTH;
+ input_direction = D_NORTH;
else if (keystate[SDLK_DOWN])
- input_direction = SOUTH;
+ input_direction = D_SOUTH;
}
}
-Point
-WorldMap::get_next_tile(Point pos, Direction direction)
+Vector
+WorldMap::get_next_tile(Vector pos, Direction direction)
{
switch(direction)
{
- case WEST:
+ case D_WEST:
pos.x -= 1;
break;
- case EAST:
+ case D_EAST:
pos.x += 1;
break;
- case NORTH:
+ case D_NORTH:
pos.y -= 1;
break;
- case SOUTH:
+ case D_SOUTH:
pos.y += 1;
break;
- case NONE:
+ case D_NONE:
break;
}
return pos;
}
bool
-WorldMap::path_ok(Direction direction, Point old_pos, Point* new_pos)
+WorldMap::path_ok(Direction direction, Vector old_pos, Vector* new_pos)
{
*new_pos = get_next_tile(old_pos, direction);
{ // Check if we the tile allows us to go to new_pos
switch(direction)
{
- case WEST:
+ case D_WEST:
return (at(old_pos)->west && at(*new_pos)->east);
- case EAST:
+ case D_EAST:
return (at(old_pos)->east && at(*new_pos)->west);
- case NORTH:
+ case D_NORTH:
return (at(old_pos)->north && at(*new_pos)->south);
- case SOUTH:
+ case D_SOUTH:
return (at(old_pos)->south && at(*new_pos)->north);
- case NONE:
+ case D_NONE:
assert(!"path_ok() can't work if direction is NONE");
}
return false;
}
void
-WorldMap::update()
+WorldMap::update(float delta)
{
if (enter_level && !tux->is_moving())
{
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+ Level* level = at_level();
+ if (level)
{
- if (i->x == tux->get_tile_pos().x &&
- i->y == tux->get_tile_pos().y)
+ if (level->x == tux->get_tile_pos().x &&
+ level->y == tux->get_tile_pos().y)
{
- std::cout << "Enter the current level: " << i->name << std::endl;;
- halt_music();
- GameSession session(datadir + "levels/" + i->name,
+ PlayerStatus old_player_status = player_status;
+
+ std::cout << "Enter the current level: " << level->name << std::endl;
+ // do a shriking fade to the level
+ shrink_fade(Vector((level->x*32 + 16 + offset.x),(level->y*32 + 16
+ + offset.y)), 500);
+ GameSession session(datadir + "/levels/" + level->name,
1, ST_GL_LOAD_LEVEL_FILE);
- session.run();
- if (1) // FIXME: insert exit status checker here
- i->solved = true;
+ switch (session.run())
+ {
+ case GameSession::ES_LEVEL_FINISHED:
+ {
+ bool old_level_state = level->solved;
+ level->solved = true;
+
+ if (session.get_world()->get_tux()->got_power !=
+ session.get_world()->get_tux()->NONE_POWER)
+ player_status.bonus = PlayerStatus::FLOWER_BONUS;
+ else if (session.get_world()->get_tux()->size == BIG)
+ player_status.bonus = PlayerStatus::GROWUP_BONUS;
+ else
+ player_status.bonus = PlayerStatus::NO_BONUS;
+
+ if (old_level_state != level->solved)
+ { // Try to detect the next direction to which we should walk
+ // FIXME: Mostly a hack
+ Direction dir = D_NONE;
+
+ Tile* tile = at(tux->get_tile_pos());
+
+ if (tile->north && tux->back_direction != D_NORTH)
+ dir = D_NORTH;
+ else if (tile->south && tux->back_direction != D_SOUTH)
+ dir = D_SOUTH;
+ else if (tile->east && tux->back_direction != D_EAST)
+ dir = D_EAST;
+ else if (tile->west && tux->back_direction != D_WEST)
+ dir = D_WEST;
+
+ if (dir != D_NONE)
+ {
+ tux->set_direction(dir);
+ //tux->update(delta);
+ }
+
+ std::cout << "Walk to dir: " << dir << std::endl;
+ }
+
+ if (!level->extro_filename.empty())
+ {
+ MusicRef theme =
+ music_manager->load_music(datadir + "/music/theme.mod");
+ music_manager->play_music(theme);
+ // Display final credits and go back to the main menu
+ display_text_file(level->extro_filename,
+ "/images/background/extro.jpg", SCROLL_SPEED_MESSAGE);
+ display_text_file("CREDITS",
+ "/images/background/oiltux.jpg", SCROLL_SPEED_CREDITS);
+ quit = true;
+ }
+ }
+
+ break;
+ case GameSession::ES_LEVEL_ABORT:
+ /* In case the player's abort the level, keep it using the old
+ status */
+ player_status = old_player_status;
+ break;
+ case GameSession::ES_GAME_OVER:
+ {
+ /* 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
+ level 1 */
+ char str[80];
+
+ DrawingContext context;
+ context.draw_gradient(Color (0, 255, 0), Color (255, 0, 255),
+ LAYER_BACKGROUND0);
+
+ context.draw_text_center(blue_text, "GAMEOVER",
+ Vector(0, 200), LAYER_FOREGROUND1);
+
+ sprintf(str, "SCORE: %d", player_status.score);
+ context.draw_text_center(gold_text, str,
+ Vector(0, 224), LAYER_FOREGROUND1);
+
+ sprintf(str, "COINS: %d", player_status.distros);
+ context.draw_text_center(gold_text, str,
+ Vector(0, screen->w - 32), LAYER_FOREGROUND1);
- play_music(song, 1);
- show_menu = 0;
- menu_reset();
+ context.do_drawing();
+
+ SDL_Event event;
+ wait_for_event(event,2000,5000,true);
+
+ quit = true;
+ player_status.reset();
+ break;
+ }
+ case GameSession::ES_NONE:
+ assert(false);
+ // Should never be reached
+ break;
+ }
+
+ music_manager->play_music(song);
+ Menu::set_current(0);
if (!savegame_file.empty())
savegame(savegame_file);
return;
}
}
- std::cout << "Nothing to enter at: "
- << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl;
+ else
+ {
+ std::cout << "Nothing to enter at: "
+ << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl;
+ }
}
else
{
+ tux->action(delta);
tux->set_direction(input_direction);
- tux->update(0.33f);
}
- if(show_menu)
+ Menu* menu = Menu::current();
+ if(menu)
{
- if(current_menu == worldmap_menu)
+ menu->action();
+
+ if(menu == worldmap_menu)
{
switch (worldmap_menu->check())
{
- case 2: // Return to game
- menu_reset();
+ case MNID_RETURNWORLDMAP: // Return to game
break;
- case 5: // Quit Worldmap
+ case MNID_QUITWORLDMAP: // Quit Worldmap
quit = true;
break;
}
}
+ else if(menu == options_menu)
+ {
+ process_options_menu();
+ }
}
}
Tile*
-WorldMap::at(Point p)
+WorldMap::at(Vector p)
{
assert(p.x >= 0
&& p.x < width
&& p.y >= 0
&& p.y < height);
- return TileManager::instance()->get(tilemap[width * p.y + p.x]);
+ int x = int(p.x);
+ int y = int(p.y);
+ return tile_manager->get(tilemap[width * y + x]);
}
WorldMap::Level*
void
-WorldMap::draw(const Point& offset)
+WorldMap::draw(DrawingContext& context, const Vector& offset)
{
for(int y = 0; y < height; ++y)
for(int x = 0; x < width; ++x)
{
- Tile* tile = at(Point(x, y));
- tile->sprite->draw(x*32 + offset.x,
- y*32 + offset.y);
+ Tile* tile = at(Vector(x, y));
+ context.draw_surface(tile->sprite,
+ Vector(x*32 + offset.x, y*32 + offset.y), LAYER_TILES);
}
for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
{
if (i->solved)
- leveldot_green->draw(i->x*32 + offset.x,
- i->y*32 + offset.y);
+ context.draw_surface(leveldot_green,
+ Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1);
else
- leveldot_red->draw(i->x*32 + offset.x,
- i->y*32 + offset.y);
+ context.draw_surface(leveldot_red,
+ Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1);
}
- tux->draw(offset);
- draw_status();
+ tux->draw(context, offset);
+ draw_status(context);
}
void
-WorldMap::draw_status()
+WorldMap::draw_status(DrawingContext& context)
{
+ context.push_transform();
+ context.set_translation(Vector(0, 0));
+
char str[80];
sprintf(str, "%d", player_status.score);
- white_text->draw("SCORE", 0, 0);
- gold_text->draw(str, 96, 0);
- sprintf(str, "%d", player_status.distros);
- white_text->draw_align("COINS", 320-64, 0, A_LEFT, A_TOP);
- gold_text->draw_align(str, 320+64, 0, A_RIGHT, A_TOP);
+ context.draw_text(white_text, "SCORE", Vector(0, 0), LAYER_FOREGROUND1);
+ context.draw_text(gold_text, str, Vector(96, 0), LAYER_FOREGROUND1);
- white_text->draw("LIVES", 480, 0);
+ sprintf(str, "%d", player_status.distros);
+ context.draw_text(white_text, "COINS", Vector(screen->w/2 - 16*5, 0),
+ LAYER_FOREGROUND1);
+ context.draw_text(gold_text, str, Vector(screen->w/2 + (16*5)/2, 0),
+ LAYER_FOREGROUND1);
+
+ context.draw_text(white_text, "LIVES",
+ Vector(screen->w - white_text->get_text_width("LIVES")*2, 0),
+ LAYER_FOREGROUND1);
if (player_status.lives >= 5)
{
sprintf(str, "%dx", player_status.lives);
- gold_text->draw(str, 585, 0);
- tux_life->draw(565+(18*3), 0);
+ context.draw_text(gold_text, str,
+ Vector(screen->w - gold_text->get_text_width(str) - tux_life->w, 0),
+ LAYER_FOREGROUND1);
+ context.draw_surface(tux_life, Vector(screen->w - gold_text->w, 0),
+ LAYER_FOREGROUND1);
}
else
{
for(int i= 0; i < player_status.lives; ++i)
- tux_life->draw(565+(18*i),0);
+ context.draw_surface(tux_life,
+ Vector(screen->w - tux_life->w*4 + (tux_life->w*i), 0),
+ LAYER_FOREGROUND1);
}
if (!tux->is_moving())
if (i->x == tux->get_tile_pos().x &&
i->y == tux->get_tile_pos().y)
{
- white_text->draw_align(i->name.c_str(), screen->w/2, screen->h, A_HMIDDLE, A_BOTTOM);
+ 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() - 50),
+ LAYER_FOREGROUND1);
break;
}
}
void
WorldMap::display()
{
- show_menu = false;
+ Menu::set_current(0);
quit = false;
- song = load_song(datadir + "/music/" + music);
- play_music(song, 1);
+ song = music_manager->load_music(datadir + "/music/" + music);
+ music_manager->play_music(song);
- while(!quit) {
- Point tux_pos = tux->get_pos();
- if (1)
- {
- offset.x = -tux_pos.x + screen->w/2;
- offset.y = -tux_pos.y + screen->h/2;
+ unsigned int last_update_time;
+ unsigned int update_time;
- if (offset.x > 0) offset.x = 0;
- if (offset.y > 0) offset.y = 0;
+ last_update_time = update_time = st_get_ticks();
- 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;
- }
+ DrawingContext context;
+ while(!quit)
+ {
+ float delta = ((float)(update_time-last_update_time))/100.0;
- draw(offset);
- get_input();
- update();
+ delta *= 1.3f;
- if(show_menu)
- {
- menu_process_current();
- mouse_cursor->draw();
- }
- flipscreen();
+ if (delta > 10.0f)
+ delta = .3f;
+
+ last_update_time = update_time;
+ update_time = st_get_ticks();
- SDL_Delay(20);
- }
+ 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;
+
+ 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(delta);
+
+ if(Menu::current())
+ {
+ Menu::current()->draw(context);
+ mouse_cursor->draw(context);
+ }
+
+ context.do_drawing();
- free_music(song);
+ SDL_Delay(20);
+ }
}
void
<< " (lives " << player_status.lives << ")\n"
<< " (score " << player_status.score << ")\n"
<< " (distros " << player_status.distros << ")\n"
- << " (tux (x " << tux->get_tile_pos().x << ") (y " << tux->get_tile_pos().y << ")"
- << " (back \"" << direction_to_string(tux->back_direction) << "\"))\n"
+ << " (tux (x " << tux->get_tile_pos().x << ") (y " << tux->get_tile_pos().y << ")\n"
+ << " (back \"" << direction_to_string(tux->back_direction) << "\")\n"
+ << " (bonus \"" << bonus_to_string(player_status.bonus) << "\"))\n"
<< " (levels\n";
for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
std::cout << "loadgame: " << filename << std::endl;
savegame_file = filename;
- if (access(filename.c_str(), F_OK) == 0)
+ if (access(filename.c_str(), F_OK) != 0)
+ return;
+
+ lisp_object_t* savegame = lisp_read_from_file(filename);
+ if (!savegame)
{
- lisp_object_t* cur = lisp_read_from_file(filename);
+ std::cout << "WorldMap:loadgame: File not found: " << filename << std::endl;
+ return;
+ }
- if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-savegame") != 0)
- return;
+ lisp_object_t* cur = savegame;
- cur = lisp_cdr(cur);
- LispReader reader(cur);
-
- reader.read_int("lives", &player_status.lives);
- reader.read_int("score", &player_status.score);
- reader.read_int("distros", &player_status.distros);
+ if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-savegame") != 0)
+ return;
- lisp_object_t* tux_cur = 0;
- if (reader.read_lisp("tux", &tux_cur))
- {
- Point p;
- LispReader tux_reader(tux_cur);
- tux_reader.read_int("x", &p.x);
- tux_reader.read_int("y", &p.y);
+ cur = lisp_cdr(cur);
+ LispReader reader(cur);
+
+ reader.read_int("lives", &player_status.lives);
+ reader.read_int("score", &player_status.score);
+ reader.read_int("distros", &player_status.distros);
+
+ if (player_status.lives < 0)
+ player_status.lives = START_LIVES;
+
+ lisp_object_t* tux_cur = 0;
+ if (reader.read_lisp("tux", &tux_cur))
+ {
+ Vector p;
+ std::string back_str = "none";
+ std::string bonus_str = "none";
+
+ LispReader tux_reader(tux_cur);
+ tux_reader.read_float("x", &p.x);
+ tux_reader.read_float("y", &p.y);
+ tux_reader.read_string("back", &back_str);
+ tux_reader.read_string("bonus", &bonus_str);
- tux->set_tile_pos(p);
- }
+ player_status.bonus = string_to_bonus(bonus_str);
+ tux->back_direction = string_to_direction(back_str);
+ tux->set_tile_pos(p);
+ }
- lisp_object_t* level_cur = 0;
- if (reader.read_lisp("levels", &level_cur))
+ lisp_object_t* level_cur = 0;
+ if (reader.read_lisp("levels", &level_cur))
+ {
+ while(level_cur)
{
- while(level_cur)
- {
- lisp_object_t* sym = lisp_car(lisp_car(level_cur));
- lisp_object_t* data = lisp_cdr(lisp_car(level_cur));
-
- if (strcmp(lisp_symbol(sym), "level") == 0)
- {
- std::string name;
- bool solved = false;
- std::string back_str ="";
- Direction back = NONE;
+ lisp_object_t* sym = lisp_car(lisp_car(level_cur));
+ lisp_object_t* data = lisp_cdr(lisp_car(level_cur));
- LispReader level_reader(data);
- level_reader.read_string("name", &name);
- level_reader.read_bool("solved", &solved);
- if (level_reader.read_string("back", &back_str))
- back = string_to_direction(back_str);
+ if (strcmp(lisp_symbol(sym), "level") == 0)
+ {
+ std::string name;
+ bool solved = false;
- std::cout << "Name: " << name << " " << solved << std::endl;
+ LispReader level_reader(data);
+ level_reader.read_string("name", &name);
+ level_reader.read_bool("solved", &solved);
- for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
- {
- if (name == i->name)
- i->solved = solved;
- }
+ for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+ {
+ if (name == i->name)
+ i->solved = solved;
}
-
- level_cur = lisp_cdr(level_cur);
}
+
+ level_cur = lisp_cdr(level_cur);
}
}
+
+ lisp_free(savegame);
}
} // namespace WorldMapNS
-/* EOF */
+/* Local Variables: */
+/* mode:c++ */
+/* End: */
+