void MapState::EnterState(Application &ctrl, SDL_Surface *screen) {
camera.Resize(screen->w, screen->h);
+ LoadMap(map);
}
void MapState::ExitState(Application &ctrl, SDL_Surface *screen) {
void MapState::Transition(Map *newMap, const Vector<int> &coordinates) {
+ UnloadMap();
Vector<int> 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));