Skip to content

Add zones to prevent player from walking through buildings.#165

Open
charmyt wants to merge 1 commit intomasterfrom
dont-walk-through-buildings
Open

Add zones to prevent player from walking through buildings.#165
charmyt wants to merge 1 commit intomasterfrom
dont-walk-through-buildings

Conversation

@charmyt
Copy link
Collaborator

@charmyt charmyt commented Sep 16, 2022

No description provided.

nx,
ny );

for(const auto& zone: blockedZones) {
Copy link
Owner

@zethon zethon Sep 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please put the { on a new line. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants