I am at the moment creating a tower protection sport as part of a bunch mission in class. This sport can be programmed in C++ utilizing SFML. We’re having bother with discovering a great way to outline the trail our enemies will take. Our maps are generated from a .txt-file:
Within the .txt-file, ! is the beginning, = is the trail, # is a wall, and ? is the tip.
This ends in a grid like this:
Our plan is so as to add the coordinates of each path-grid as nodes to a linked checklist. The enemies would then need to observe the nodes within the checklist.
Up to now we’ve tried so as to add the nodes to a linked checklist whereas producing the map. The map is generated by studying the .txt-file line-by-line (left-to-right and top-to-bottom).
if (file.is_open()) {
whereas(getline(file, line)) {
for (auto &ch : line) {
if (ch == '!') {
tiles_.push_back(
std::make_shared<GameCell>("property/street.png", y, x, true, false, true));
} else if (ch == '#') {
tiles_.push_back(
std::make_shared<GameCell>("property/grass.png", y, x, false, false, false));
} else if (ch == '?') {
tiles_.push_back(
std::make_shared<GameCell>("property/street.png", y, x, true, true, false));
} else if (ch == '=') {
tiles_.push_back(
std::make_shared<GameCell>("property/street.png", y, x, true, false, false));
}
y += 100;
}
x += 100;
y = 0;
}
file.shut();
}
The issue with that is that it solely works if the trail goes proper and down. If the trail goes left or up the nodes find yourself within the flawed order within the linked checklist.
How can we order the nodes the appropriate means? Or are there higher methods of doing this?