TileMap::TileMap(const TileSet *new_tileset) :
tileset(new_tileset),
tiles(),
- solid(false),
+ real_solid(false),
+ effective_solid(false),
speed_x(1),
speed_y(1),
width(0),
TileMap::TileMap(const Reader& reader) :
tileset(),
tiles(),
- solid(false),
+ real_solid(false),
+ effective_solid(false),
speed_x(1),
speed_y(1),
width(-1),
assert(tileset != NULL);
reader.get("name", name);
- reader.get("solid", solid);
+ reader.get("solid", real_solid);
reader.get("speed", speed_x);
reader.get("speed-y", speed_y);
z_pos = reader_get_layer (reader, /* default = */ 0);
- if(solid && ((speed_x != 1) || (speed_y != 1))) {
+ if(real_solid && ((speed_x != 1) || (speed_y != 1))) {
log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl;
speed_x = 1;
speed_y = 1;
current_alpha = alpha;
}
+ /* Initialize effective_solid based on real_solid and current_alpha. */
+ effective_solid = real_solid;
+ update_effective_solid ();
+
reader.get("width", width);
reader.get("height", height);
if(width < 0 || height < 0)
bool solid, size_t width, size_t height) :
tileset(new_tileset),
tiles(),
- solid(solid),
+ real_solid(solid),
+ effective_solid(solid),
speed_x(1),
speed_y(1),
width(0),
if (amt > 0) current_alpha = std::min(current_alpha + amt, alpha);
if (amt < 0) current_alpha = std::max(current_alpha + amt, alpha);
}
- if ((alpha < 0.25) && (current_alpha < 0.25)) set_solid(false);
- if ((alpha > 0.75) && (current_alpha > 0.75)) set_solid(true);
+ update_effective_solid ();
}
movement = Vector(0,0);
z_pos = LAYER_GUI - 100;
else
z_pos = new_z_pos;
- solid = newsolid;
+ real_solid = newsolid;
+ update_effective_solid ();
// make sure all tiles are loaded
for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
void
TileMap::set_solid(bool solid)
{
- this->solid = solid;
+ this->real_solid = solid;
+ update_effective_solid ();
}
uint32_t
this->alpha = alpha;
this->current_alpha = alpha;
this->remaining_fade_time = 0;
- if (current_alpha < 0.25) set_solid(false);
- if (current_alpha > 0.75) set_solid(true);
+ update_effective_solid ();
}
float
return this->current_alpha;
}
+/*
+ * Private methods
+ */
+void
+TileMap::update_effective_solid (void)
+{
+ if (!real_solid)
+ effective_solid = false;
+ else if (effective_solid && (current_alpha < .25))
+ effective_solid = false;
+ else if (!effective_solid && (current_alpha >= .75))
+ effective_solid = true;
+}
/* EOF */
{ return z_pos; }
bool is_solid() const
- { return solid; }
+ { return real_solid && effective_solid; }
/**
* Changes Tilemap's solidity, i.e. whether to consider it when doing collision detection.
typedef std::vector<uint32_t> Tiles;
Tiles tiles;
- bool solid;
+ /* read solid: In *general*, is this a solid layer?
+ * effective solid: is the layer *currently* solid? A generally solid layer
+ * may be not solid when its alpha is low.
+ * See `is_solid' above. */
+ bool real_solid;
+ bool effective_solid;
+ void update_effective_solid (void);
+
float speed_x;
float speed_y;
int width, height;