master
MitchellHansen 9 years ago
parent 17207d8294
commit 98b3e75503

@ -34,7 +34,7 @@ void App::Input() {
explorer->setDestination(sf::Vector2i(20, 20)); explorer->setDestination(sf::Vector2i(20, 20));
} }
if (event.key.code == sf::Keyboard::W) { 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) { if (event.key.code == sf::Keyboard::E) {
explorer->setDestination(sf::Vector2i(100, 12)); explorer->setDestination(sf::Vector2i(100, 12));

@ -27,34 +27,32 @@ void Explorer::setDestination(sf::Vector2i destination_) {
bool Explorer::move() { bool Explorer::move() {
// While there are moves for us to take // While there are moves for us to take
if (!movement_stack.empty()) { if (!movement_stack.empty()) {
bool valid = false; // If the next move is valid, collision bool valid = false; // If the next move is valid, collision
int x = movement_stack.back(); int x = movement_stack.back();
switch (x) { switch (x) {
case 0: case 0: // North
break;
case 1: // North
if (!map->getTile(position.x, position.y - 1)->isSolid()) { if (!map->getTile(position.x, position.y - 1)->isSolid()) {
valid = true; valid = true;
position = sf::Vector2i(position.x, position.y - 1); position = sf::Vector2i(position.x, position.y - 1);
} }
break; break;
case 2: // East case 1: // East
if (!map->getTile(position.x + 1, position.y)->isSolid()) { if (!map->getTile(position.x + 1, position.y)->isSolid()) {
valid = true; valid = true;
position = sf::Vector2i(position.x + 1, position.y); position = sf::Vector2i(position.x + 1, position.y);
} }
break; break;
case 3: // South case 2: // South
if (!map->getTile(position.x, position.y + 1)->isSolid()) { if (!map->getTile(position.x, position.y + 1)->isSolid()) {
valid = true; valid = true;
position = sf::Vector2i(position.x, position.y + 1); position = sf::Vector2i(position.x, position.y + 1);
} }
break; break;
case 4: // West case 3: // West
if (!map->getTile(position.x - 1, position.y)->isSolid()) { if (!map->getTile(position.x - 1, position.y)->isSolid()) {
valid = true; valid = true;
position = sf::Vector2i(position.x - 1, position.y); position = sf::Vector2i(position.x - 1, position.y);
@ -74,6 +72,7 @@ bool Explorer::move() {
// If everything went well, pop and return true // If everything went well, pop and return true
movement_stack.pop_back(); movement_stack.pop_back();
return true; return true;
} }
else else

@ -33,7 +33,7 @@ void node::neighbors() {
double v = dv; double v = dv;
// Take that value and create a new node // 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 // Set that tile as visited so we don't get stuck in a loop
pather->visitedMap(dest0XY.x, dest0XY.y) = 1; pather->visitedMap(dest0XY.x, dest0XY.y) = 1;
@ -51,7 +51,7 @@ void node::neighbors() {
double v = dv; double v = dv;
// Take that value and create a new node // 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 // Set that tile as visited so we don't get stuck in a loop
pather->visitedMap(dest1XY.x, dest1XY.y) = 1; pather->visitedMap(dest1XY.x, dest1XY.y) = 1;
@ -69,7 +69,7 @@ void node::neighbors() {
double v = dv; double v = dv;
// Take that value and create a new node // 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 // Set that tile as visited so we don't get stuck in a loop
pather->visitedMap(dest2XY.x, dest2XY.y) = 1; pather->visitedMap(dest2XY.x, dest2XY.y) = 1;
@ -87,7 +87,7 @@ void node::neighbors() {
double v = dv; double v = dv;
// Take that value and create a new node // 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 // Set that tile as visited so we don't get stuck in a loop
pather->visitedMap(dest3XY.x, dest3XY.y) = 1; pather->visitedMap(dest3XY.x, dest3XY.y) = 1;

Loading…
Cancel
Save