2023-05-08 18:20:55 +02:00
|
|
|
#include "player.hpp"
|
2023-06-08 00:54:01 +02:00
|
|
|
#include "../../config.h"
|
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,
|
2023-06-10 14:48:16 +02:00
|
|
|
sf::Vector2f spawnPosition)
|
2023-06-03 19:33:41 +02:00
|
|
|
{
|
2023-06-10 14:48:16 +02:00
|
|
|
playerId = playerCreationCounter++;
|
|
|
|
this->spawnPosition = spawnPosition;
|
|
|
|
coordinates->set(spawnPosition);
|
2023-06-03 19:33:41 +02:00
|
|
|
|
|
|
|
input = std::move(assignedInput);
|
|
|
|
|
2023-06-11 14:03:48 +02:00
|
|
|
auto sprite = std::make_shared<VersatileSprite>(skinRessourceName, getIsoSize());
|
|
|
|
addChildScreenOffset(sprite, IsometricCoordinates(-getIsoSize() / 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-11 14:03:48 +02:00
|
|
|
return getIsoSize();
|
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
|
|
|
|
2023-06-08 00:54:01 +02:00
|
|
|
if (input->isPerformingAction(GameAction::JUMP))
|
|
|
|
{
|
|
|
|
coordinates->move({0, 0, 10});
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-06-10 14:48:16 +02:00
|
|
|
|
|
|
|
int Player::getPlayerId() const
|
|
|
|
{
|
|
|
|
return playerId;
|
|
|
|
}
|
2023-06-10 18:51:23 +02:00
|
|
|
|
2023-06-11 14:03:48 +02:00
|
|
|
float Player::getWorldRadius() const
|
2023-06-10 18:51:23 +02:00
|
|
|
{
|
2023-06-11 14:03:48 +02:00
|
|
|
return radiusInWorld;
|
2023-06-10 18:51:23 +02:00
|
|
|
}
|
|
|
|
|
2023-06-11 14:03:48 +02:00
|
|
|
sf::Vector2f Player::getIsoSize() const
|
2023-06-10 18:51:23 +02:00
|
|
|
{
|
2023-06-11 14:03:48 +02:00
|
|
|
// TODO: For some reason, the player is a little to narrow. This fixes it.
|
|
|
|
const float fixFactor = 1.4f;
|
|
|
|
float width = radiusInWorld * 2.f * WORLD_TO_ISO_SCALE * fixFactor;
|
|
|
|
return {width, width * ISOMETRIC_SKEW};
|
2023-06-10 18:51:23 +02:00
|
|
|
}
|