From da3d1154b1cae255fcbe9ae1dd759c6cabedbef7 Mon Sep 17 00:00:00 2001 From: florianf Date: Tue, 2 Mar 2010 11:22:41 +0000 Subject: [PATCH] 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. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6509 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/supertux/sector.cpp | 21 +++++++++++++++++++++ src/supertux/sector.hpp | 2 ++ 2 files changed, 23 insertions(+) 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(); /** -- 2.11.0