2019-06-06 17:07:24 +02:00
|
|
|
//
|
|
|
|
// Created by trotfunky on 06/06/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Entity.h"
|
2019-06-07 02:59:27 +02:00
|
|
|
|
|
|
|
const std::map<std::string,EntityType> Entity::entityTypeLookup = {
|
|
|
|
{"Citizen",EntityType::Citizen},
|
2019-06-07 22:20:34 +02:00
|
|
|
{"Significant",EntityType::Significant},
|
2019-06-07 02:59:27 +02:00
|
|
|
{"House",EntityType::House},
|
|
|
|
{"Car",EntityType::Car}};
|
|
|
|
|
2019-06-07 22:20:34 +02:00
|
|
|
Entity::Entity(int x, int y, EntityType type, sf::Texture* texture, int width, int height) : type(type)
|
2019-06-07 02:59:27 +02:00
|
|
|
{
|
2019-06-07 22:20:34 +02:00
|
|
|
shape = sf::RectangleShape(sf::Vector2f(width*pro_maat::pixelsPerUnit,height*pro_maat::pixelsPerUnit));
|
|
|
|
// Sets the origin at the center of the entity
|
|
|
|
shape.setOrigin(shape.getSize()/2.0f);
|
|
|
|
// Adjust position for offset origin
|
|
|
|
shape.setPosition((x+0.5*width)*pro_maat::pixelsPerUnit,(y+0.5*width)*pro_maat::pixelsPerUnit);
|
|
|
|
shape.setTexture(texture);
|
|
|
|
|
|
|
|
currentState = State::Idle;
|
|
|
|
nextState = State::Idle;
|
|
|
|
target = sf::Vector2i(shape.getPosition());
|
|
|
|
nextTarget = target;
|
2019-06-07 02:59:27 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 22:20:34 +02:00
|
|
|
Entity::Entity(const pugi::xml_node& entityNode, sf::Texture* texture)
|
|
|
|
: Entity(entityNode.attribute("x").as_int(),
|
|
|
|
entityNode.attribute("y").as_int(),
|
|
|
|
entityTypeLookup.at(entityNode.attribute("type").as_string()),
|
|
|
|
texture,
|
|
|
|
entityNode.attribute("w").as_int(1),
|
|
|
|
entityNode.attribute("h").as_int(1)) {}
|
2019-06-07 02:59:27 +02:00
|
|
|
|
|
|
|
void Entity::move()
|
|
|
|
{
|
2019-06-07 22:20:34 +02:00
|
|
|
// FIXME : Testing purposes
|
|
|
|
shape.setRotation(shape.getRotation()+90);
|
2019-06-07 02:59:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Entity::update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const sf::RectangleShape& Entity::getShape() const
|
|
|
|
{
|
|
|
|
return(shape);
|
|
|
|
}
|