X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Ftilemap.cpp;h=ed3d4723f827996cd4e5c68f5a93e3b1e519380b;hb=f2ffe3ee4a4955232ac311c661f98e11d2daa155;hp=6f2019588aa67a0d292a3ff26065edf0a5d0aeca;hpb=fff6a103cf0873ea6e72148500d8259d12d86418;p=supertux.git diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 6f2019588..ed3d4723f 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -26,18 +26,19 @@ #include "util/reader.hpp" TileMap::TileMap(const TileSet *new_tileset) : - tileset(new_tileset), + tileset(new_tileset), tiles(), - solid(false), - speed_x(1), - speed_y(1), + real_solid(false), + effective_solid(false), + speed_x(1), + speed_y(1), width(0), - height(0), - z_pos(0), + height(0), + z_pos(0), offset(Vector(0,0)), movement(0,0), drawing_effect(NO_EFFECT), - alpha(1.0), + alpha(1.0), current_alpha(1.0), remaining_fade_time(0), path(), @@ -49,17 +50,18 @@ TileMap::TileMap(const TileSet *new_tileset) : TileMap::TileMap(const Reader& reader) : tileset(), tiles(), - solid(false), - speed_x(1), - speed_y(1), + real_solid(false), + effective_solid(false), + speed_x(1), + speed_y(1), width(-1), - height(-1), - z_pos(0), + height(-1), + z_pos(0), offset(Vector(0,0)), - movement(Vector(0,0)), + movement(Vector(0,0)), drawing_effect(NO_EFFECT), - alpha(1.0), - current_alpha(1.0), + alpha(1.0), + current_alpha(1.0), remaining_fade_time(0), path(), walker(), @@ -69,25 +71,18 @@ TileMap::TileMap(const Reader& reader) : assert(tileset != NULL); reader.get("name", name); - reader.get("z-pos", z_pos); - reader.get("solid", solid); + reader.get("solid", real_solid); reader.get("speed", speed_x); reader.get("speed-y", speed_y); - - if(solid && ((speed_x != 1) || (speed_y != 1))) { + + z_pos = reader_get_layer (reader, /* default = */ 0); + + 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; } - if (z_pos > (LAYER_GUI - 100)) { - log_warning << "z-pos of " - << ((name == "") ? "unnamed tilemap" : name) << " (" << z_pos << ") " - << "is too large. " - << "Clipping to " << (LAYER_GUI - 100) << "." << std::endl; - z_pos = LAYER_GUI - 100; - } - const lisp::Lisp* pathLisp = reader.get_lisp("path"); if (pathLisp) { path.reset(new Path()); @@ -106,6 +101,10 @@ TileMap::TileMap(const Reader& reader) : 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) @@ -130,25 +129,28 @@ TileMap::TileMap(const Reader& reader) : } if(empty) + { log_info << "Tilemap '" << name << "', z-pos '" << z_pos << "' is empty." << std::endl; + } } TileMap::TileMap(const TileSet *new_tileset, std::string name, int z_pos, bool solid, size_t width, size_t height) : - tileset(new_tileset), + tileset(new_tileset), tiles(), - solid(solid), - speed_x(1), - speed_y(1), + real_solid(solid), + effective_solid(solid), + speed_x(1), + speed_y(1), width(0), - height(0), - z_pos(z_pos), + height(0), + z_pos(z_pos), offset(Vector(0,0)), movement(Vector(0,0)), - drawing_effect(NO_EFFECT), - alpha(1.0), + drawing_effect(NO_EFFECT), + alpha(1.0), current_alpha(1.0), - remaining_fade_time(0), + remaining_fade_time(0), path(), walker(), draw_target(DrawingContext::NORMAL) @@ -178,15 +180,14 @@ TileMap::update(float elapsed_time) 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); // if we have a path to follow, follow it if (walker.get()) { Vector v = walker->advance(elapsed_time); - movement = Vector(v.x-get_offset().x, std::max(0.0f,v.y-get_offset().y)); + movement = v - get_offset(); set_offset(v); } } @@ -295,7 +296,8 @@ TileMap::set(int newwidth, int newheight, const std::vector&newt, 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) @@ -350,7 +352,8 @@ TileMap::get_tiles_overlapping(const Rectf &rect) const void TileMap::set_solid(bool solid) { - this->solid = solid; + this->real_solid = solid; + update_effective_solid (); } uint32_t @@ -419,21 +422,33 @@ TileMap::fade(float alpha, float seconds) this->remaining_fade_time = seconds; } -void +void TileMap::set_alpha(float alpha) { 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 +float TileMap::get_alpha() { 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 */