Works
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user