qt - Find coordinates in a vector c++ -


i'm creating game in qt in c++, , store every coordinate of specific size vector :

 std::vector<std::unique_ptr<tile>> all_tiles = createworld(bgtile);      for(auto & tile : all_tiles) {         tiles.push_back(std::move(tile));     } 

each level has healthpacks stored in vector aswell.

std::vector<std::unique_ptr<enemy>> all_enemies = getenemies(nrofenemies);      for(auto &healthpackuniqueptr : all_healthpacks) {         std::shared_ptr<tile> healthpackptr{std::move(healthpackuniqueptr)};         int x = healthpackptr->getxpos();         int y = healthpackptr->getypos();         int newypos=checkoverlappos(healthpackptr->getxpos(),healthpackptr->getypos());         newypos = checkoverlapenemy(healthpackptr->getxpos(),newypos);         auto healthpack = std::make_shared<healthpack>(healthpackptr->getxpos(), newypos, healthpackptr->getvalue());         healthpacks.push_back(healthpack);     } 

but know i'm searching fastest way check if player position @ healthpack position. have search on 2 values in vector : x , y position. suggestion how this?

your 'real' question:

i have search on 2 values in vector : x , y position. suggestion how this?"

is classic xy question, i'm ignoring it!

i'm searching fastest way check if player position @ healthpack position.

now we're talking. approach using won't scale number of items increase, , you'll need similar every pair of objects interested in. not good.

thankfully problem has been solved (and improved upon) decades, need use spacial partitioning scheme such bsp, bvh, quadtree/octree, etc. beauty of these schemes single data structure can hold entire world in it, making arbitrary item intersection queries trivial (and fast).


Comments

Popular posts from this blog

javascript - How to process users in one specific order using map o each function? -

java - Two interface have same method name with different return type -

javascript - Linking from page A to a specific iframe on page B -