X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=5ced57b06b61e41432c66186816a0e3174585c2f;hb=c174dfb2a675b039e915e01549950c7a5b554492;hp=3b3cbc8f5033a26619b944626158c575b3324cec;hpb=a983f6648d43492632c41e2b7519b70458b53cf4;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index 3b3cbc8f5..5ced57b06 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -177,6 +177,7 @@ Sector::parse_object(const std::string& name, const lisp::Lisp& reader) void Sector::parse(const lisp::Lisp& sector) { + bool has_background = false; lisp::ListIterator iter(§or); while(iter.next()) { const std::string& token = iter.item(); @@ -202,11 +203,22 @@ Sector::parse(const lisp::Lisp& sector) } else { GameObject* object = parse_object(token, *(iter.lisp())); if(object) { + if(dynamic_cast(object)) { + has_background = true; + } else if(dynamic_cast(object)) { + has_background = true; + } add_object(object); } } } + if(!has_background) { + Gradient* gradient = new Gradient(); + gradient->set_gradient(Color(0.3, 0.4, 0.75), Color(1, 1, 1)); + add_object(gradient); + } + update_game_objects(); if(solid_tilemaps.size() < 1) log_warning << "sector '" << name << "' does not contain a solid tile layer." << std::endl; @@ -684,6 +696,18 @@ Sector::update_game_objects() gameobjects.push_back(object); } gameobjects_new.clear(); + + /* update solid_tilemaps list */ + //FIXME: this could be more efficient + solid_tilemaps.clear(); + for(std::vector::iterator i = gameobjects.begin(); + i != gameobjects.end(); ++i) + { + TileMap* tm = dynamic_cast(*i); + if (!tm) continue; + if (tm->is_solid()) solid_tilemaps.push_back(tm); + } + } bool @@ -1184,6 +1208,10 @@ Sector::collision_static_constrains(MovingObject& object) } } +namespace { + const float MAX_SPEED = 16.0f; +} + void Sector::handle_collisions() { @@ -1193,6 +1221,13 @@ Sector::handle_collisions() for(MovingObjects::iterator i = moving_objects.begin(); i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; + Vector mov = moving_object->get_movement(); + + // make sure movement is never faster than MAX_SPEED. Norm is pretty fat, so two addl. checks are done before. + if (((mov.x > MAX_SPEED * M_SQRT1_2) || (mov.y > MAX_SPEED * M_SQRT1_2)) && (mov.norm() > MAX_SPEED)) { + moving_object->movement = mov.unit() * MAX_SPEED; + //log_debug << "Temporarily reduced object's speed of " << mov.norm() << " to " << moving_object->movement.norm() << "." << std::endl; + } moving_object->dest = moving_object->get_bbox(); moving_object->dest.move(moving_object->get_movement()); @@ -1288,7 +1323,7 @@ Sector::handle_collisions() } bool -Sector::is_free_of_tiles(const Rect& rect) const +Sector::is_free_of_tiles(const Rect& rect, const bool ignoreUnisolid) const { using namespace collision; @@ -1313,7 +1348,8 @@ Sector::is_free_of_tiles(const Rect& rect) const Constraints constraints; return collision::rectangle_aatriangle(&constraints, rect, triangle); } - if(tile->getAttributes() & Tile::SOLID) return false; + if((tile->getAttributes() & Tile::SOLID) && !ignoreUnisolid) return false; + if((tile->getAttributes() & Tile::SOLID) && !(tile->getAttributes() & Tile::UNISOLID)) return false; } } } @@ -1322,11 +1358,11 @@ Sector::is_free_of_tiles(const Rect& rect) const } bool -Sector::is_free_of_statics(const Rect& rect, const MovingObject* ignore_object) const +Sector::is_free_of_statics(const Rect& rect, const MovingObject* ignore_object, const bool ignoreUnisolid) const { using namespace collision; - if (!is_free_of_tiles(rect)) return false; + if (!is_free_of_tiles(rect, ignoreUnisolid)) return false; for(MovingObjects::const_iterator i = moving_objects.begin(); i != moving_objects.end(); ++i) {