From: Florian Forster Date: Tue, 2 Mar 2010 11:22:41 +0000 (+0000) Subject: supertux/sector.[ch]pp: Implemented the get_nearby_objects() method. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=208f8912e8b7568821be0b636cca273eba8f7ffd;p=supertux.git supertux/sector.[ch]pp: Implemented the get_nearby_objects() method. This method returns all moving objects close to a given point. Among other things, this may be the player and walking badguys. SVN-Revision: 6509 --- diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 6cc7c7a9d..e57058f7e 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -1923,5 +1923,26 @@ Sector::get_nearest_player (const Vector& pos) return (nearest_player); } /* Player *get_nearest_player */ +std::vector +Sector::get_nearby_objects (const Vector& center, float max_distance) +{ + std::vector ret; + std::vector players = Sector::current()->get_players(); + + for (size_t i = 0; i < players.size (); i++) { + float distance = players[i]->get_bbox ().distance (center); + if (distance <= max_distance) + ret.push_back (players[i]); + } + + for (size_t i = 0; i < moving_objects.size (); i++) { + float distance = moving_objects[i]->get_bbox ().distance (center); + if (distance <= max_distance) + ret.push_back (moving_objects[i]); + } + + return (ret); +} + /* vim: set sw=2 sts=2 et : */ /* EOF */ diff --git a/src/supertux/sector.hpp b/src/supertux/sector.hpp index 69f2d7041..7016653b4 100644 --- a/src/supertux/sector.hpp +++ b/src/supertux/sector.hpp @@ -165,6 +165,8 @@ public: return (get_nearest_player (get_anchor_pos (pos, ANCHOR_MIDDLE))); } + std::vector get_nearby_objects (const Vector& center, float max_distance); + Rectf get_active_region(); /**