{
for(std::list<TileMap*>::iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
+
for(size_t x=0; x < solids->get_width(); ++x) {
for(size_t y=0; y < solids->get_height(); ++y) {
const Tile* tile = solids->get_tile(x, y);
camera->get_translation() + Vector(1600, 1200));
}
+namespace {
+ bool is_tilemap_solid(const TileMap* tm) { return tm->is_solid(); }
+ bool is_tilemap_nonsolid(const TileMap* tm) { return !tm->is_solid(); }
+}
+
+void
+Sector::update_solid_tilemap_list()
+{
+
+ // remove non-solid tilemaps from list
+ solid_tilemaps.erase(std::remove_if(solid_tilemaps.begin(), solid_tilemaps.end(), is_tilemap_nonsolid), solid_tilemaps.end());
+
+ // if tilemaps are to be added, create new list of solid tilemaps
+ if (solid_tilemaps.size() != (unsigned int)std::count_if(tilemaps.begin(), tilemaps.end(), is_tilemap_solid)) {
+ log_debug << "Found new solid tilemaps - this is eeevil! Re-creating list of solid tilemaps." << std::endl;
+ solid_tilemaps.clear();
+ for(std::list<TileMap*>::iterator i = tilemaps.begin(); i != tilemaps.end(); i++) {
+ TileMap* tm = *i;
+ if (tm->is_solid()) solid_tilemaps.push_back(tm);
+ }
+ }
+
+}
+
void
Sector::update(float elapsed_time)
{
player->check_bounds(camera);
+ // update solid_tilemaps list
+ update_solid_tilemap_list();
+
/* update objects */
for(GameObjects::iterator i = gameobjects.begin();
i != gameobjects.end(); ++i) {
}
TileMap* tilemap = dynamic_cast<TileMap*> (object);
- if(tilemap != NULL && tilemap->is_solid()) {
- solid_tilemaps.push_back(tilemap);
+ if(tilemap != NULL) {
+ tilemaps.push_back(tilemap);
+ if (tilemap->is_solid()) solid_tilemaps.push_back(tilemap);
}
Camera* camera = dynamic_cast<Camera*> (object);
if(portable != NULL) {
portables.erase(std::find(portables.begin(), portables.end(), portable));
}
+ TileMap* tilemap = dynamic_cast<TileMap*> (object);
+ if(tilemap != NULL) {
+ tilemaps.erase(std::find(tilemaps.begin(), tilemaps.end(), tilemap));
+ if (tilemap->is_solid()) solid_tilemaps.erase(std::find(solid_tilemaps.begin(), solid_tilemaps.end(), tilemap));
+ }
Bullet* bullet = dynamic_cast<Bullet*> (object);
if(bullet != NULL) {
bullets.erase(std::find(bullets.begin(), bullets.end(), bullet));
{
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
+
bool horizontally = ((rect.p2.x >= 0 + solids->get_x_offset()) && (rect.p1.x <= solids->get_width() * 32 + solids->get_x_offset()));
bool vertically = (rect.p1.y <= solids->get_height() * 32 + solids->get_y_offset());
if (horizontally && vertically) return true;
float width = 0;
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
+
if ((solids->get_width() * 32 + solids->get_x_offset()) > width) width = (solids->get_width() * 32 + solids->get_x_offset());
}
return width;
float height = 0;
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
+
if ((solids->get_height() * 32 + solids->get_y_offset()) > height) height = (solids->get_height() * 32 + solids->get_y_offset());
}
return height;
{
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
+
solids->change_all(old_tile_id, new_tile_id);
}
}
void try_unexpose(GameObject* object);
void try_expose_me();
void try_unexpose_me();
+
+ /**
+ * Adds solid tilemaps to list, removes non-solid ones
+ */
+ void update_solid_tilemap_list();
/** Checks for all possible collisions. And calls the
collision_handlers, which the collision_objects provide for this
// some special objects, where we need direct access
// (try to avoid accessing them directly)
Player* player;
- std::list<TileMap*> solid_tilemaps;
+ std::list<TileMap*> tilemaps; /**< list of all tilemaps in this sector */
+ std::list<TileMap*> solid_tilemaps; /**< list of tilemaps to consider for collision detection */
Camera* camera;
};