@@ -18,58 +18,3 @@ bool FollowMotion::chase(GameWorld &world, Player *ghost) {
18
18
19
19
return true ;
20
20
}
21
-
22
- Pos FollowMotion::findNextPos (const GameWorld &world, const Pos &from, const Pos &to) {
23
- if (from == to) {
24
- return from;
25
- }
26
-
27
- // Get Cached entities, in map
28
- std::map<Pos, std::shared_ptr<Entity>> entities = world.getScreenMap ();
29
-
30
-
31
- std::list<std::shared_ptr<TPosFind>> toCheck;
32
- toCheck.push_back (std::make_shared<TPosFind>(TPosFind (from, nullptr )));
33
-
34
- std::set<Pos> seen;
35
-
36
- Pos posLeft (-1 , 0 );
37
- Pos posUp (0 , -1 );
38
- Pos posRight (1 , 0 );
39
- Pos posDown (0 , 1 );
40
-
41
- while (!toCheck.empty ()) {
42
- std::shared_ptr<TPosFind> posCheck = toCheck.front ();
43
-
44
- if (seen.find (posCheck->m_Pos ) == seen.end ()) {
45
- if (posCheck->m_Pos == to) {
46
- std::shared_ptr<TPosFind> parent = posCheck;
47
- while (parent->m_PosFrom != nullptr && parent->m_PosFrom ->m_PosFrom != nullptr ) {
48
- parent = parent->m_PosFrom ;
49
- }
50
- return parent->m_Pos ;
51
- }
52
-
53
- std::shared_ptr<Entity> entLeft = GameMap::getScreenAt (entities, posCheck->m_Pos + posLeft);
54
- if (entLeft->getType () != Entity::EBorder)
55
- toCheck.push_back (std::make_shared<TPosFind>(TPosFind (entLeft->getPos (), posCheck)));
56
-
57
- std::shared_ptr<Entity> entUp = GameMap::getScreenAt (entities, posCheck->m_Pos + posUp);
58
- if (entUp->getType () != Entity::EBorder)
59
- toCheck.push_back (std::make_shared<TPosFind>(TPosFind (entUp->getPos (), posCheck)));
60
-
61
- std::shared_ptr<Entity> entRight = GameMap::getScreenAt (entities, posCheck->m_Pos + posRight);
62
- if (entRight->getType () != Entity::EBorder)
63
- toCheck.push_back (std::make_shared<TPosFind>(TPosFind (entRight->getPos (), posCheck)));
64
-
65
- std::shared_ptr<Entity> entDown = GameMap::getScreenAt (entities, posCheck->m_Pos + posDown);
66
- if (entDown->getType () != Entity::EBorder)
67
- toCheck.push_back (std::make_shared<TPosFind>(TPosFind (entDown->getPos (), posCheck)));
68
-
69
- seen.emplace (posCheck->m_Pos );
70
- }
71
- toCheck.pop_front ();
72
- }
73
-
74
- return {0 , 0 };
75
- }
0 commit comments