Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/worldmap/tux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Tux::Tux(WorldMap* worldmap) :
m_direction(Direction::NONE),
m_initial_tile_pos(),
m_tile_pos(),
m_last_stable_tile_pos(),
m_last_level_tile_pos(),
m_last_stable_back_direction(Direction::NONE),
m_last_level_back_direction(Direction::NONE),
m_offset(0),
m_moving(false),
m_ghost_mode(false)
Expand Down Expand Up @@ -300,9 +304,20 @@ Tux::try_continue_walking(float dt_sec)
(teleporter) ||
m_ghost_mode)
{
if (special_tile && !special_tile->get_map_message().empty() && !special_tile->is_passive_message()) {
m_worldmap->set_passive_message({}, 0.0f);
}
if (special_tile && !special_tile->get_map_message().empty() && !special_tile->is_passive_message())
{
m_worldmap->set_passive_message("", 0.0f);
}

if (worldmap_sector->at_object<LevelTile>() != nullptr)
{
m_last_level_tile_pos = m_tile_pos;
m_last_level_back_direction = m_back_direction;
}

m_last_stable_tile_pos = m_ghost_mode ? m_last_level_tile_pos : m_tile_pos;
m_last_stable_back_direction = m_ghost_mode ? m_last_level_back_direction : m_back_direction;
}

stop();
return;
Expand Down Expand Up @@ -392,6 +407,20 @@ Tux::setup()
if (m_initial_tile_pos != Vector())
m_tile_pos = m_initial_tile_pos;

m_last_stable_tile_pos = m_tile_pos;
m_last_stable_back_direction = m_back_direction;

if (m_worldmap->get_sector().at_object<LevelTile>(m_tile_pos))
{
m_last_level_tile_pos = m_tile_pos;
m_last_level_back_direction = m_back_direction;
}
else
{
m_last_level_tile_pos = m_last_stable_tile_pos;
m_last_level_back_direction = m_last_stable_back_direction;
}

// check if we already touch a SpriteChange object
auto sprite_change = m_worldmap->get_sector().at_object<SpriteChange>(m_tile_pos);
change_sprite(sprite_change);
Expand Down
16 changes: 16 additions & 0 deletions src/worldmap/tux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ class Tux final : public GameObject
inline void set_initial_pos(const Vector& pos) { m_initial_tile_pos = pos / 32.f; }
inline void set_tile_pos(const Vector& pos) { m_tile_pos = pos; }

inline Vector get_last_stable_tile_pos() const { return m_last_stable_tile_pos; }
inline void set_last_stable_tile_pos(const Vector& pos) { m_last_stable_tile_pos = pos; }

inline Vector get_last_level_tile_pos() const { return m_last_level_tile_pos; }
inline void set_last_level_tile_pos(const Vector& pos) { m_last_level_tile_pos = pos; }

inline Direction get_last_stable_back_direction() const { return m_last_stable_back_direction; }
inline void set_last_stable_back_direction(Direction dir) { m_last_stable_back_direction = dir; }

inline Direction get_last_level_back_direction() const { return m_last_level_back_direction; }
inline void set_last_level_back_direction(Direction dir) { m_last_level_back_direction = dir; }

void process_special_tile(SpecialTile* special_tile);

private:
Expand All @@ -78,6 +90,10 @@ class Tux final : public GameObject
Direction m_direction;
Vector m_initial_tile_pos;
Vector m_tile_pos;
Vector m_last_stable_tile_pos;
Vector m_last_level_tile_pos;
Direction m_last_stable_back_direction;
Direction m_last_level_back_direction;
/** Length by which tux is away from its current tile, length is in
input_direction direction */
float m_offset;
Expand Down
24 changes: 20 additions & 4 deletions src/worldmap/worldmap_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,35 @@ WorldMapState::load_tux(const ssq::Table& table)
Vector p(0.0f, 0.0f);
if (!tux.get("x", p.x) || !tux.get("y", p.y))
Comment thread
MatusGuy marked this conversation as resolved.
{
log_warning << "Player position not set, respawning." << std::endl;
sector.move_to_spawnpoint(DEFAULT_SPAWNPOINT_NAME);
m_position_was_reset = true;
return;
Comment thread
joanasaraiva10 marked this conversation as resolved.
}

std::string back_str;
tux.get("back", back_str);
sector.m_tux->m_back_direction = string_to_direction(back_str);
sector.m_tux->set_tile_pos(p);
Direction back_dir = string_to_direction(back_str);

int tile_data = sector.tile_data_at(p);
if (!(tile_data & (Tile::WORLDMAP_NORTH | Tile::WORLDMAP_SOUTH | Tile::WORLDMAP_WEST | Tile::WORLDMAP_EAST)))
{
log_warning << "Player at illegal position " << p.x << ", " << p.y << " respawning." << std::endl;
sector.move_to_spawnpoint(DEFAULT_SPAWNPOINT_NAME);
m_position_was_reset = true;
return;
}

sector.m_tux->m_back_direction = back_dir;
sector.m_tux->set_tile_pos(p);
sector.m_tux->set_last_stable_tile_pos(p);
sector.m_tux->set_last_stable_back_direction(back_dir);

if (sector.at_object<LevelTile>(p))
{
sector.m_tux->set_last_level_tile_pos(p);
sector.m_tux->set_last_level_back_direction(back_dir);
}
}

Expand Down Expand Up @@ -296,10 +309,13 @@ WorldMapState::save_state(bool initial) const
sector_table.set("music", music_object.get_music());

/** Save Tux **/
const Vector save_pos = sector.m_tux->get_last_stable_tile_pos();
const Direction save_back = sector.m_tux->get_last_stable_back_direction();

ssq::Table tux = sector_table.addTable("tux");
tux.set("x", sector.m_tux->get_tile_pos().x);
tux.set("y", sector.m_tux->get_tile_pos().y);
tux.set("back", direction_to_string(sector.m_tux->m_back_direction));
tux.set("x", save_pos.x);
tux.set("y", save_pos.y);
tux.set("back", direction_to_string(save_back));

/** Save levels **/
ssq::Table levels = sector_table.addTable("levels");
Expand Down