From 98b3e755036da11fe99ea69f7d58e754606be535 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sat, 22 Aug 2015 16:09:20 -0700 Subject: [PATCH] Works --- aStar/App.cpp | 2 +- aStar/Explorer.cpp | 13 ++++++------- aStar/Pather.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/aStar/App.cpp b/aStar/App.cpp index d167f8d..7661621 100644 --- a/aStar/App.cpp +++ b/aStar/App.cpp @@ -34,7 +34,7 @@ void App::Input() { explorer->setDestination(sf::Vector2i(20, 20)); } if (event.key.code == sf::Keyboard::W) { - explorer->setDestination(sf::Vector2i(200, 200)); + explorer->setDestination(sf::Vector2i(50, 50)); } if (event.key.code == sf::Keyboard::E) { explorer->setDestination(sf::Vector2i(100, 12)); diff --git a/aStar/Explorer.cpp b/aStar/Explorer.cpp index 6de2b8b..27cab6a 100644 --- a/aStar/Explorer.cpp +++ b/aStar/Explorer.cpp @@ -27,34 +27,32 @@ void Explorer::setDestination(sf::Vector2i destination_) { bool Explorer::move() { + // While there are moves for us to take if (!movement_stack.empty()) { bool valid = false; // If the next move is valid, collision int x = movement_stack.back(); switch (x) { - case 0: - break; - - case 1: // North + case 0: // North if (!map->getTile(position.x, position.y - 1)->isSolid()) { valid = true; position = sf::Vector2i(position.x, position.y - 1); } break; - case 2: // East + case 1: // East if (!map->getTile(position.x + 1, position.y)->isSolid()) { valid = true; position = sf::Vector2i(position.x + 1, position.y); } break; - case 3: // South + case 2: // South if (!map->getTile(position.x, position.y + 1)->isSolid()) { valid = true; position = sf::Vector2i(position.x, position.y + 1); } break; - case 4: // West + case 3: // West if (!map->getTile(position.x - 1, position.y)->isSolid()) { valid = true; position = sf::Vector2i(position.x - 1, position.y); @@ -74,6 +72,7 @@ bool Explorer::move() { // If everything went well, pop and return true movement_stack.pop_back(); + return true; } else diff --git a/aStar/Pather.cpp b/aStar/Pather.cpp index 3b616d6..07a15e2 100644 --- a/aStar/Pather.cpp +++ b/aStar/Pather.cpp @@ -33,7 +33,7 @@ void node::neighbors() { double v = dv; // Take that value and create a new node - pather->openList.emplace(new node(dest0XY, v, 3, 1, pather->active_node, pather), v); + pather->openList.emplace(new node(dest0XY, v, 0, 1, pather->active_node, pather), v); // Set that tile as visited so we don't get stuck in a loop pather->visitedMap(dest0XY.x, dest0XY.y) = 1; @@ -51,7 +51,7 @@ void node::neighbors() { double v = dv; // Take that value and create a new node - pather->openList.emplace(new node(dest1XY, v, 4, 1, pather->active_node, pather), v); + pather->openList.emplace(new node(dest1XY, v, 1, 1, pather->active_node, pather), v); // Set that tile as visited so we don't get stuck in a loop pather->visitedMap(dest1XY.x, dest1XY.y) = 1; @@ -69,7 +69,7 @@ void node::neighbors() { double v = dv; // Take that value and create a new node - pather->openList.emplace(new node(dest2XY, v, 1, 1, pather->active_node, pather), v); + pather->openList.emplace(new node(dest2XY, v, 2, 1, pather->active_node, pather), v); // Set that tile as visited so we don't get stuck in a loop pather->visitedMap(dest2XY.x, dest2XY.y) = 1; @@ -87,7 +87,7 @@ void node::neighbors() { double v = dv; // Take that value and create a new node - pather->openList.emplace(new node(dest3XY, v, 2, 1, pather->active_node, pather), v); + pather->openList.emplace(new node(dest3XY, v, 3, 1, pather->active_node, pather), v); // Set that tile as visited so we don't get stuck in a loop pather->visitedMap(dest3XY.x, dest3XY.y) = 1;