-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathWalker.cpp
65 lines (60 loc) · 1.76 KB
/
Walker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "mapgen/Walker.hpp"
#include "mapgen/City.hpp"
#include "mapgen/MapGenerator.hpp"
#include "mapgen/utils.hpp"
#include <SFML/Graphics.hpp>
#include <random>
template <typename Iter>
Iter Walker::select_randomly(Iter start, Iter end) {
std::uniform_int_distribution<> dis(0, std::distance(start, end) - 1);
std::random_device gen;
std::advance(start, dis(gen));
return start;
}
Walker::Walker(City *c, MapGenerator *m) : mapgen(m) {
// road = *mapgen->select_randomly(s->roads.begin(), s->roads.end());
reverse = rand() % 2 == 0;
shape = new sf::CircleShape(3);
shape->setFillColor(sf::Color(225,225,190));
shape->setOutlineColor(sf::Color::Black);
shape->setOutlineThickness(1);
road = *select_randomly(c->roads.begin(), c->roads.end());
reverse = road->regions.back()->city == c;
if (reverse) {
// step = road->spline->getInterpolatedPositionCount() - 1;
}
}
Road* Walker::getNextRoad() {
City* c;
if (!reverse) {
c = road->regions.back()->city;
} else {
c = road->regions.front()->city;
}
if (c == nullptr) {
mg::warn("city", "nullptr");
} else if (c->roads.size() == 0) {
mg::warn(c->typeName, "without roads");
}
road = *select_randomly(c->roads.begin(), c->roads.end());
reverse = road->regions.back()->city == c;
if (reverse) {
// step = road->spline->getInterpolatedPositionCount() - 1;
} else {
step = 0;
}
return road;
}
//TODO: fix road->spline
void Walker::tick() {
// if ((step == road->spline->getInterpolatedPositionCount() && !reverse) || (step == 0 && reverse)) {
// getNextRoad();
// }
// auto p = road->spline->getInterpolatedPosition(step);
// shape->setPosition(sf::Vector2f(p.x - 1.5, p.y - 1.5));
// if (!reverse) {
// step++;
// } else {
// step--;
// }
}