Given a N number of surfaces within a grid, each one being a game obstacle where collision makes itself an unavoidable necessity, how can I detect the collision of a player or any game object if the whole map or grid of surfaces is being drawn through iteration? Suppose that the whole map has a total of 20 tiles of walls (The grid has "free spaces" displaced randomly between the walls creating paths), now imagine that each tile is a surface (a loaded image), and that their x and y positions are being set through iteration (Considering that the map is actually a XML file from Tiled software, and, therefore, there's iteration because of the necessity of reading).
These 20 tiles, each one with their own x and y positions (and width and height) need to be detected by the player or game object. Considering that I'm programming in Python and that each one of these tiles are stored in a list, I can easily iterate through all of them... But then comes the problem:
If I iterate through all the tiles and get the x and y positions through the index, I can't test wether the player is above or below or left or right anything, because all the tiles are being accessed "at once"! (Not technically speaking) At the same time, I need to iterate over everything, because the map could have 3000x3000 tiles. If I test if the player is above the index y position, the condition will be true many times because there'll be many tiles below it as a whole.
I did not post any code because the whole is quite complex, and I'm afraid I would not make myself sufficiently clear (I don't know if I've made it anyway). It's a complex problem and I'm still trying to solve it. I had the idea of "projecting" an invisible tile at the next position of the player considering it's moving-direction in the grid to test wether there is an obstacle-tile there or not, but I'm still thinking about it.
I appreciate any idea/comment, for it would be much helpful.