A* working : previousNode was initialized with one step instead of none.

This commit is contained in:
Teo-CD 2019-06-09 05:37:08 +02:00
parent d42d176e8d
commit ebc8d961f4
2 changed files with 12 additions and 5 deletions

View file

@ -19,10 +19,9 @@ Entity::Entity(int x, int y, EntityType type, sf::Texture* texture, int width, i
shape.setPosition((x+0.5*width)*pro_maat::pixelsPerUnit,(y+0.5*width)*pro_maat::pixelsPerUnit);
shape.setTexture(texture);
// FIXME : Testing purposes
currentState = State::Moving;
currentState = State::Idle;
nextState = State::Idle;
target = pro_maat::GridPos(x+10,y);
target = pro_maat::GridPos(x,y);
nextTarget = target;
}
@ -62,7 +61,10 @@ void Entity::move(Orientation orientation)
}
void Entity::update()
{}
{
currentState = nextState;
target = nextTarget;
}
const sf::RectangleShape& Entity::getShape() const
{

View file

@ -120,8 +120,13 @@ Orientation Level::findPath(pro_maat::GridPos start, pro_maat::GridPos goal, int
if(std::find(goalNeighboursBeginIterator,goalNeighboursEndIterator,currentNode) != goalNeighboursEndIterator)
{
if(currentNode == start)
{
return(Orientation::None);
}
// Trace back to the start
pro_maat::GridPos& previousNode = paths[currentNode];
pro_maat::GridPos& previousNode = currentNode;
for(;paths[previousNode]!=start;previousNode = paths[previousNode])
{}