Add zones to prevent player from walking through buildings.#165
Add zones to prevent player from walking through buildings.#165
Conversation
| nx, | ||
| ny ); | ||
|
|
||
| for(const auto& zone: blockedZones) { |
There was a problem hiding this comment.
When I was thinking about this my plan was to put the x,y cords of the blocked zones tiles into a two dimensional map-like structure so that way the search for a blocked tile could be faster than a linear search.
For example: you could have something like: std::map<int, std::set<int>> _bt // blocked tiles and then you would populate it with the x,y coords of the blocked tiles (this would require some computation but would only have to be done at load).
So now when the user takes a step, you get the tile the user wants to move to and then see if that tile is in that structure:
if (bt.find(x) != bt.end() && bt[x].find(y) != bt[x].end()) // the cord was found, which means its a blocked tile and the user can't step there
This should be O(log N) as opposed to the code you have which is O(N).
Also, you might want to look around for a better structure than the map of sets I used here, there's probably something better suited to this than this hack I threw together.
| nx, | ||
| ny ); | ||
|
|
||
| for(const auto& zone: blockedZones) { |
There was a problem hiding this comment.
Also, please put the { on a new line. :)
No description provided.