Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <list>
- #include <map>
- class Node {
- public:
- float cout_g, cout_h, cout_f;
- sf::Vector2i parent;
- };
- class Pathfinding
- {
- public:
- Pathfinding(sf::Vector2i);
- std::list<sf::Vector2i> searchPath(sf::Vector2i endpoint,sf::Vector2i startpoint);
- private:
- std::map<sf::Vector2i,Node> closedList;
- std::map<sf::Vector2i,Node> openList;
- };
- #include "Pathfinding.h"
- Pathfinding::Pathfinding(sf::Vector2i coords)
- {
- }
- std::list<sf::Vector2i> Pathfinding::searchPath(sf::Vector2i endpoint, sf::Vector2i startpoint)
- {
- Node startNode;
- startNode.parent.x = 0;
- startNode.parent.y = 0;
- openList[startpoint] = startNode;
- std::list<sf::Vector2i> list;
- return list;
- }
- #include "Pathfinding.h"
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800,600),"A* Test");
- Pathfinding pathfinder(sf::Vector2i(800,600));
- while(window.isOpen())
- {
- sf::Event event;
- while(window.pollEvent(event))
- {
- if(event.type == sf::Event::Closed) window.close();
- }
- std::list<sf::Vector2i> path = pathfinder.searchPath(sf::Vector2i(3,3),sf::Vector2i(45,55));
- window.clear(sf::Color::White);
- window.display();
- }
- return 0;
- }
- openList[startpoint] = startNode;
- namespace std
- {
- template <class T>
- struct hash<sf::Vector2<T>>
- {
- std::size_t operator()(const sf::Vector2<T>& v) const
- {
- using std::hash;
- // Compute individual hash values for first
- // and second. Combine them using the Boost-func
- std::size_t tmp0 = hash<T>()(v.x);
- std::size_t tmp1 = hash<T>()(v.y);
- tmp0 ^= tmp1 + 0x9e3779b9 + (tmp0 << 6) + (tmp0 >> 2);
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement