diff --git a/lib/Ray/sources/Controllers/Gamepad.cpp b/lib/Ray/sources/Controllers/Gamepad.cpp index b51bcc95..7845411e 100644 --- a/lib/Ray/sources/Controllers/Gamepad.cpp +++ b/lib/Ray/sources/Controllers/Gamepad.cpp @@ -42,3 +42,8 @@ void RAY::Controller::GamePad::setID(int id) { this->_id = id; } + +float RAY::Controller::GamePad::getAxisValue(int index) +{ + return GetGamepadAxisMovement(this->_id, index); +} \ No newline at end of file diff --git a/lib/Ray/sources/Controllers/Gamepad.hpp b/lib/Ray/sources/Controllers/Gamepad.hpp index 893c674f..9f17acc8 100644 --- a/lib/Ray/sources/Controllers/Gamepad.hpp +++ b/lib/Ray/sources/Controllers/Gamepad.hpp @@ -17,6 +17,7 @@ namespace RAY::Controller { class GamePad { public: typedef ::GamepadButton Button; + typedef ::GamepadAxis Axis; //! @brief A default constructor //! @param The id of the controller @@ -44,6 +45,9 @@ namespace RAY::Controller { //! @param Button The keycode of the button bool isReleased(Button); + //! @brief Get the value of an axis + float getAxisValue(int index); + //! @brief Returns true if Button is up on the gamepad //! @param Button The keycode of the button bool isUp(Button); diff --git a/sources/Component/Gamepad/GamepadComponent.hpp b/sources/Component/Gamepad/GamepadComponent.hpp index be00a49b..3825645d 100644 --- a/sources/Component/Gamepad/GamepadComponent.hpp +++ b/sources/Component/Gamepad/GamepadComponent.hpp @@ -10,6 +10,7 @@ #include "Entity/Entity.hpp" using Button = RAY::Controller::GamePad::Button; +using Axis = RAY::Controller::GamePad::Axis; using Gamepad = RAY::Controller::GamePad; namespace BBM @@ -35,6 +36,11 @@ namespace BBM //! @brief move down key Button keyDown = GAMEPAD_BUTTON_LEFT_FACE_DOWN; + Axis LeftStickX = GAMEPAD_AXIS_LEFT_X; + Axis LeftStickY = GAMEPAD_AXIS_LEFT_Y; + Axis RightStickX = GAMEPAD_AXIS_RIGHT_X; + Axis RightStickY = GAMEPAD_AXIS_RIGHT_Y; + //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index d6a20b6d..6a047352 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -76,7 +76,8 @@ namespace BBM .addComponent("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() .addComponent() - .addComponent() + //.addComponent() + .addComponent(0) .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() @@ -96,6 +97,7 @@ namespace BBM .addComponent(WAL::Callback(), &MapGenerator::wallCollide, -1, 3);*/ std::srand(std::time(nullptr)); MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); + return scene; } diff --git a/sources/System/Gamepad/GamepadSystem.cpp b/sources/System/Gamepad/GamepadSystem.cpp index f6d67d99..ee4b8767 100644 --- a/sources/System/Gamepad/GamepadSystem.cpp +++ b/sources/System/Gamepad/GamepadSystem.cpp @@ -31,10 +31,11 @@ namespace BBM for (auto key : keyPressedMap) key.second = gamepad.isPressed(key.first); - controllable.move = Vector2f(); - controllable.move.x += gamepad.isPressed(gamepadComponent.keyRight); - controllable.move.x -= gamepad.isPressed(gamepadComponent.keyLeft); - controllable.move.y += gamepad.isPressed(gamepadComponent.keyUp); - controllable.move.y -= gamepad.isPressed(gamepadComponent.keyDown); + controllable.move.x = gamepad.getAxisValue(gamepadComponent.LeftStickX) * -1; + controllable.move.y = gamepad.getAxisValue(gamepadComponent.LeftStickY) * -1; + controllable.move.x -= gamepad.isDown(gamepadComponent.keyRight); + controllable.move.x += gamepad.isDown(gamepadComponent.keyLeft); + controllable.move.y += gamepad.isDown(gamepadComponent.keyUp); + controllable.move.y -= gamepad.isDown(gamepadComponent.keyDown); } } \ No newline at end of file