Added representation of occupied squares and a way to retrieve them for A* implementation
Updated UML
This commit is contained in:
parent
115af7dcc7
commit
430d2b0307
6 changed files with 95 additions and 5 deletions
|
@ -35,12 +35,13 @@ 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)
|
||||
{
|
||||
case Orientation::Nort:
|
||||
case Orientation::North:
|
||||
movementVector.y = -pro_maat::pixelsPerUnit;
|
||||
break;
|
||||
case Orientation::East:
|
||||
|
@ -64,3 +65,36 @@ const sf::RectangleShape& Entity::getShape() const
|
|||
{
|
||||
return(shape);
|
||||
}
|
||||
|
||||
const State Entity::getState() const
|
||||
{
|
||||
return currentState;
|
||||
}
|
||||
|
||||
const sf::Vector2i 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;
|
||||
return sf::Vector2i(x,y);
|
||||
}
|
||||
|
||||
const std::vector<std::pair<uint8_t, uint8_t>> Entity::getOccupiedSquares() const
|
||||
{
|
||||
std::vector<std::pair<uint8_t, uint8_t>> 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;
|
||||
|
||||
for(int i = 0;i<w;i++)
|
||||
{
|
||||
for(int j = 0;j<h;j++)
|
||||
{
|
||||
occupiedSquares.emplace_back(x+i,y+j);
|
||||
}
|
||||
}
|
||||
|
||||
return std::move(occupiedSquares);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue