A* implementation
Working except for end of path endless loop (0,0 point appearing in paths for no reason?) Commit mainly because the HDD is on the verge of dying
This commit is contained in:
parent
250a680cad
commit
d42d176e8d
9 changed files with 181 additions and 29 deletions
|
@ -19,9 +19,10 @@ 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);
|
||||
|
||||
currentState = State::Idle;
|
||||
// FIXME : Testing purposes
|
||||
currentState = State::Moving;
|
||||
nextState = State::Idle;
|
||||
target = pro_maat::GridPos(x,y);
|
||||
target = pro_maat::GridPos(x+10,y);
|
||||
nextTarget = target;
|
||||
}
|
||||
|
||||
|
@ -36,7 +37,6 @@ Entity::Entity(const pugi::xml_node& entityNode, sf::Texture* texture)
|
|||
void Entity::move(Orientation orientation)
|
||||
{
|
||||
// TODO : Add speed ?
|
||||
shape.setRotation(static_cast<float>(orientation));
|
||||
|
||||
sf::Vector2f movementVector(0,0);
|
||||
switch (orientation)
|
||||
|
@ -53,8 +53,11 @@ void Entity::move(Orientation orientation)
|
|||
case Orientation::West:
|
||||
movementVector.x = -pro_maat::pixelsPerUnit;
|
||||
break;
|
||||
case Orientation::None:
|
||||
return;
|
||||
}
|
||||
|
||||
shape.setRotation(static_cast<float>(orientation));
|
||||
shape.setPosition(shape.getPosition()+movementVector);
|
||||
}
|
||||
|
||||
|
@ -74,19 +77,22 @@ const State Entity::getState() const
|
|||
const pro_maat::GridPos Entity::getPosition() const
|
||||
{
|
||||
// Safe : size is a multiple of pro_maat::pixelsPerUnit
|
||||
uint8_t x = (shape.getPosition().x-0.5*shape.getSize().x)/pro_maat::pixelsPerUnit;
|
||||
uint8_t y = (shape.getPosition().y-0.5*shape.getSize().y)/pro_maat::pixelsPerUnit;
|
||||
pro_maat::GridUnit x = shape.getPosition().x/pro_maat::pixelsPerUnit;
|
||||
pro_maat::GridUnit y = shape.getPosition().y/pro_maat::pixelsPerUnit;
|
||||
return pro_maat::GridPos(x,y);
|
||||
}
|
||||
|
||||
const std::vector<pro_maat::GridPos> Entity::getOccupiedSquares() const
|
||||
{
|
||||
std::vector<pro_maat::GridPos> occupiedSquares;
|
||||
|
||||
// Safe : size is a multiple of pro_maat::pixelsPerUnit
|
||||
uint8_t w = shape.getSize().x/pro_maat::pixelsPerUnit;
|
||||
uint8_t h = shape.getSize().y/pro_maat::pixelsPerUnit;
|
||||
uint8_t x = shape.getPosition().x/pro_maat::pixelsPerUnit - 0.5*w;
|
||||
uint8_t y = shape.getPosition().y/pro_maat::pixelsPerUnit - 0.5*h;
|
||||
pro_maat::GridUnit w = shape.getSize().x/pro_maat::pixelsPerUnit;
|
||||
pro_maat::GridUnit h = shape.getSize().y/pro_maat::pixelsPerUnit;
|
||||
pro_maat::GridUnit x = shape.getPosition().x/pro_maat::pixelsPerUnit - 0.5*w;
|
||||
pro_maat::GridUnit y = shape.getPosition().y/pro_maat::pixelsPerUnit - 0.5*h;
|
||||
|
||||
occupiedSquares.reserve(w*h);
|
||||
|
||||
for(int i = 0;i<w;i++)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue