{
if (!tumbling)
{
- direction = {0,0};
-
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
- {
- direction.y -= 1;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
- {
- direction.y += 1;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
+ if (!sf::Joystick::isConnected(0))
{
- direction.x += 1;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
- {
- direction.x -= 1;
- }
+ direction = {0,0};
- // If the vector is diagonal, normalize its length
- if (abs(direction.x) + abs(direction.y) == 2)
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
+ {
+ direction.y -= 1;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
+ {
+ direction.y += 1;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
+ {
+ direction.x += 1;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
+ {
+ direction.x -= 1;
+ }
+
+ // If the vector is diagonal, normalize its length
+ if (abs(direction.x) + abs(direction.y) == 2)
+ {
+ direction.x *= M_SQRT1_2;
+ direction.y *= M_SQRT1_2;
+ }
+ }
+ else
{
- direction.x *= M_SQRT1_2;
- direction.y *= M_SQRT1_2;
+ direction = {
+ sf::Joystick::getAxisPosition(0, sf::Joystick::X) / 100,
+ sf::Joystick::getAxisPosition(0, sf::Joystick::Y) / 100
+ };
+
+ float len{pow(direction.x, 2) + pow(direction.y, 2)};
+ if (len > 1)
+ {
+ direction.x /= sqrt(len);
+ direction.y /= sqrt(len);
+ }
+ std::cout << "x: " << direction.x << "Y: " << direction.y << std::endl;
}
}
}