Checking if something is near you with SFML

I am writing a Rougelike Game in C++ with SFML and want to know how to make it so that the game checks what object is up to 20 pixels above/below or 13 pixels left/right of you. Any code or advice would be greatly appreciated.
It really depends in what data type you are storing the objects.

If you don't have them sorted in any way, then the complexity of a search will be linear in the number of objects.

A good way of storing them is a quad tree, in this case you only have to check the objects in your square, and the adjacent squares -- this will be some constant number of squares, but still may require a large number of checks unless there is a limit on the number of objects occupying a square. Look up quad trees, as there are lots of ways to optimize this.

You can do other things too, like sorting objects by lexicographical position.

Hopefully this gives you somewhere to start.
Topic archived. No new replies allowed.