2023-05-08 18:20:55 +02:00
|
|
|
#include "player.hpp"
|
2023-05-10 14:51:09 +02:00
|
|
|
|
2023-05-17 23:22:45 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2023-05-10 14:51:09 +02:00
|
|
|
sf::Vector2f Player::getTrackablePosition() const
|
|
|
|
{
|
|
|
|
return coordinates.isometric().toScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Vector2f Player::getTrackableSize() const
|
|
|
|
{
|
|
|
|
// TODO: Proper implementation
|
2023-05-25 22:40:26 +02:00
|
|
|
return {circle->getRadius() * 2.f, circle->getRadius() * 2.f};
|
2023-05-10 14:51:09 +02:00
|
|
|
}
|
|
|
|
|
2023-05-24 14:00:51 +02:00
|
|
|
void Player::update()
|
2023-05-10 14:51:09 +02:00
|
|
|
{
|
2023-05-25 22:40:26 +02:00
|
|
|
if (!input->isActive)
|
|
|
|
{
|
2023-05-20 00:10:03 +02:00
|
|
|
isActive = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-20 17:08:47 +02:00
|
|
|
auto moveDirection = input->direction.asIsometricVector();
|
2023-05-29 00:22:36 +02:00
|
|
|
auto moveDelta = moveDirection * speed * FRAME_TIME.asSeconds();
|
2023-05-10 14:51:09 +02:00
|
|
|
coordinates.move(moveDelta);
|
|
|
|
circle->coordinates.set(coordinates);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::draw(sf::RenderWindow *window) const
|
|
|
|
{
|
|
|
|
circle->draw(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
Player::~Player()
|
|
|
|
{
|
|
|
|
delete circle;
|
|
|
|
}
|
|
|
|
|
2023-05-17 23:22:45 +02:00
|
|
|
Player::Player(std::shared_ptr<InputIdentity> assignedInput, const sf::Color color, WorldCoordinates initCoordinates)
|
2023-05-10 14:51:09 +02:00
|
|
|
{
|
|
|
|
coordinates.set(initCoordinates);
|
|
|
|
|
2023-05-17 23:22:45 +02:00
|
|
|
input = std::move(assignedInput);
|
|
|
|
|
2023-05-14 22:23:25 +02:00
|
|
|
circle = new CircleObject(10, color);
|
2023-05-10 14:51:09 +02:00
|
|
|
circle->coordinates.set(coordinates);
|
|
|
|
}
|
2023-05-24 01:15:05 +02:00
|
|
|
|
|
|
|
TrackableState Player::getTrackableState() const
|
|
|
|
{
|
|
|
|
if (isActive)
|
|
|
|
{
|
|
|
|
return TrackableState::TRACKING;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return TrackableState::END_TRACKING;
|
|
|
|
}
|
|
|
|
}
|