2023-05-08 18:20:55 +02:00
|
|
|
#include "player.hpp"
|
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
|
|
|
|
return {static_cast<float>(circle->getRadius() * 2), static_cast<float>(circle->getRadius() * 2)};
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::update(Game *game)
|
|
|
|
{
|
2023-05-17 14:13:39 +02:00
|
|
|
// Get gamepad input
|
|
|
|
std::shared_ptr<InputIdentity> gamepadIdentity = nullptr;
|
|
|
|
for (auto inputIdentity: InputMapper::getInstance()->getAllInputIdentities())
|
|
|
|
{
|
|
|
|
if (inputIdentity->deviceType == InputDeviceType::GAMEPAD)
|
|
|
|
{
|
|
|
|
gamepadIdentity = inputIdentity;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gamepadIdentity == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// auto moveDirection = InputMapper::getInstance()->getInputIdentity(InputDeviceType::KEYBOARD)->direction.asVector();
|
|
|
|
auto moveDirection = gamepadIdentity->direction.asScreenVector();
|
2023-05-14 22:23:25 +02:00
|
|
|
auto moveDelta = moveDirection * 30.0f * 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player::Player(const sf::Color color, WorldCoordinates initCoordinates)
|
|
|
|
{
|
|
|
|
coordinates.set(initCoordinates);
|
|
|
|
|
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);
|
|
|
|
}
|