Yeah, this really isn't wanting to work. Gonna need to probably redo everything
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "Explorer.h"
|
||||
#include <iostream>
|
||||
#include "Pather.h"
|
||||
|
||||
Explorer::Explorer(Map* map_) {
|
||||
color = sf::Color::Blue;
|
||||
position = sf::Vector2i(10, 10);
|
||||
position = sf::Vector2i(6, 10);
|
||||
map = map_;
|
||||
}
|
||||
|
||||
@@ -19,34 +20,41 @@ sf::Color Explorer::getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
void Explorer::setDestination(sf::Vector2i destination_) {
|
||||
plan(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.top();
|
||||
int x = movement_stack.back();
|
||||
|
||||
switch (x) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 0: // North
|
||||
case 1: // North
|
||||
if (!map->getTile(position.x, position.y - 1)->isSolid()) {
|
||||
valid = true;
|
||||
position = sf::Vector2i(position.x, position.y - 1);
|
||||
}
|
||||
break;
|
||||
case 1: // East
|
||||
case 2: // East
|
||||
if (!map->getTile(position.x + 1, position.y)->isSolid()) {
|
||||
valid = true;
|
||||
position = sf::Vector2i(position.x + 1, position.y);
|
||||
}
|
||||
break;
|
||||
case 2: // South
|
||||
case 3: // South
|
||||
if (!map->getTile(position.x, position.y + 1)->isSolid()) {
|
||||
valid = true;
|
||||
position = sf::Vector2i(position.x, position.y + 1);
|
||||
}
|
||||
break;
|
||||
case 3: // West
|
||||
case 4: // West
|
||||
if (!map->getTile(position.x - 1, position.y)->isSolid()) {
|
||||
valid = true;
|
||||
position = sf::Vector2i(position.x - 1, position.y);
|
||||
@@ -58,14 +66,14 @@ bool Explorer::move() {
|
||||
if (!valid) {
|
||||
std::cout << "Path blocked" << std::endl;
|
||||
// Flush the moves list
|
||||
while(!movement_stack.empty()) {
|
||||
movement_stack.pop();
|
||||
while (!movement_stack.empty()) {
|
||||
movement_stack.pop_back();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// If everything went well, pop and return true
|
||||
movement_stack.pop();
|
||||
movement_stack.pop_back();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -74,7 +82,8 @@ bool Explorer::move() {
|
||||
|
||||
// A*
|
||||
bool Explorer::plan(sf::Vector2i destination_) {
|
||||
|
||||
Pather pather(map);
|
||||
movement_stack = pather.pathTo(position, destination_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user