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-06-05 00:12:17 +02:00
|
|
|
Player::Player(std::shared_ptr<InputIdentity> assignedInput, const std::string &skinRessourceName,
|
|
|
|
WorldCoordinates initCoordinates)
|
2023-06-03 19:33:41 +02:00
|
|
|
{
|
|
|
|
coordinates->set(initCoordinates);
|
|
|
|
|
|
|
|
input = std::move(assignedInput);
|
|
|
|
|
2023-06-05 00:12:17 +02:00
|
|
|
auto sprite = std::make_shared<VersatileSprite>(skinRessourceName, sf::Vector2f{width, width});
|
|
|
|
addChildScreenOffset(sprite, {-width / 2.f, -width / 2.f});
|
2023-06-03 19:33:41 +02:00
|
|
|
}
|
|
|
|
|
2023-05-10 14:51:09 +02:00
|
|
|
sf::Vector2f Player::getTrackablePosition() const
|
|
|
|
{
|
2023-05-29 21:39:18 +02:00
|
|
|
return coordinates->isometric().toScreen();
|
2023-05-10 14:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sf::Vector2f Player::getTrackableSize() const
|
|
|
|
{
|
2023-06-03 20:29:24 +02:00
|
|
|
return {width, width};
|
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-30 02:13:10 +02:00
|
|
|
setActive(false);
|
2023-05-20 00:10:03 +02:00
|
|
|
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-29 21:39:18 +02:00
|
|
|
coordinates->move(moveDelta);
|
2023-06-04 20:55:14 +02:00
|
|
|
|
|
|
|
GameObject::update();
|
2023-05-10 14:51:09 +02:00
|
|
|
}
|
|
|
|
|
2023-05-24 01:15:05 +02:00
|
|
|
TrackableState Player::getTrackableState() const
|
|
|
|
{
|
2023-05-30 02:13:10 +02:00
|
|
|
if (getActive())
|
2023-05-24 01:15:05 +02:00
|
|
|
{
|
|
|
|
return TrackableState::TRACKING;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
return TrackableState::END_TRACKING;
|
|
|
|
}
|
|
|
|
}
|