X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmap%2FMapState.cpp;h=7e6d7328d2756bb533527cf41efc25a9a2b6f703;hb=7fb774ec1df3d550cd8a6805bdc69c11ad36e498;hp=8c5ef6bcf1c53ec612c3ba86d043b003127563b8;hpb=d8d0982340fc10e5161251a4b50223fabc7b4431;p=l2e.git diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 8c5ef6b..7e6d732 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -37,6 +37,7 @@ MapState::MapState(Map *map) void MapState::EnterState(Application &ctrl, SDL_Surface *screen) { camera.Resize(screen->w, screen->h); + LoadMap(map); } void MapState::ExitState(Application &ctrl, SDL_Surface *screen) { @@ -287,17 +288,28 @@ void MapState::StopFollowers(Entity &e) { void MapState::Transition(Map *newMap, const Vector &coordinates) { + UnloadMap(); Vector position(coordinates * map->Tileset()->Size()); - entities.clear(); for (Entity *e(controlled); e; e = e->Follower()) { e->Position() = position; e->SetOrientation(controlled->GetOrientation()); - entities.push_back(e); } - map = newMap; + LoadMap(newMap); skipLock = true; } +void MapState::UnloadMap() { + entities.clear(); +} + +void MapState::LoadMap(Map *m) { + map = m; + entities.insert(entities.end(), m->EntitiesBegin(), m->EntitiesEnd()); + for (Entity *e(controlled); e; e = e->Follower()) { + entities.push_back(e); + } +} + void MapState::Render(SDL_Surface *screen) { SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));