holesome/src/game/player/player.cpp

55 lines
1.4 KiB
C++
Raw Normal View History

2023-05-08 18:20:55 +02:00
#include "player.hpp"
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)
{
// 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();
2023-05-17 14:41:30 +02:00
auto moveDirection = gamepadIdentity->direction.asVector();
auto moveDelta = moveDirection * 30.0f * FRAME_TIME.asSeconds();
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);
circle = new CircleObject(10, color);
circle->coordinates.set(coordinates);
}