From ebc8d961f4506a63cf582c6d2813476752283525 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 9 Jun 2019 05:37:08 +0200 Subject: [PATCH] A* working : previousNode was initialized with one step instead of none. --- src/Entity.cpp | 10 ++++++---- src/Level.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Entity.cpp b/src/Entity.cpp index 163bcd9..9bbb7c2 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -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 { diff --git a/src/Level.cpp b/src/Level.cpp index 5a446b0..fdf3713 100644 --- a/src/Level.cpp +++ b/src/Level.cpp @@ -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]) {}