mapMonster.SetAnimation(&mapMonsterAnimation);
mapMonster.Position() = Vector<float>(64, 32);
mapMonster.SetOrientation(Entity::ORIENTATION_SOUTH);
+ map1.SetEntities(&mapMonster, 1);
InitScreen screen(width, height);
} else {
MapState *mapState(new MapState(&map1));
- mapState->AddEntity(&mapMaxim);
- mapState->AddEntity(&mapSelan);
- mapState->AddEntity(&mapGuy);
- mapState->AddEntity(&mapDekar);
-
mapState->ControlEntity(&mapMaxim);
mapState->SetWalkingSpeed(walkSpeed);
-
- mapState->AddEntity(&mapMonster);
mapMonster.StartAnimation(*mapState);
state = mapState;
, numAreas(0)
, triggers(0)
, numTriggers(0)
+, entities(0)
+, numEntities(0)
, width(0) {
}
Trigger *TriggerAt(const geometry::Vector<int> &);
geometry::Vector<int> TileCoordinates(const geometry::Vector<int> &) const;
+ Entity **EntitiesBegin() { return &entities; }
+ Entity **EntitiesEnd() { return (&entities) + numEntities; }
+
void Render(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
void RenderDebug(SDL_Surface *dest, const geometry::Vector<int> &offset) const;
void SetTileset(const graphics::Sprite *t) { tileset = t; }
void SetAreas(Area *a, int num) { areas = a; numAreas = num; }
void SetTriggers(Trigger *t, int num) { triggers = t; numTriggers = num; }
+ void SetEntities(Entity *e, int num) { entities = e; numEntities = num; }
void SetWidth(int w) { width = w; }
private:
int numAreas;
Trigger *triggers;
int numTriggers;
+ Entity *entities;
+ int numEntities;
int width;
};
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));
private:
static bool ZCompare(const Entity *lhs, const Entity *rhs);
+ void UnloadMap();
+ void LoadMap(Map *);
+
bool CheckBlocking() const;
void OnTileLock();