mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-29 17:02:11 +00:00
adding joystick support for gamepad controller
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -76,7 +76,8 @@ namespace BBM
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<AnimatorComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
//.addComponent<KeyboardComponent>()
|
||||
.addComponent<GamepadComponent>(0)
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
||||
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||
.addComponent<MovableComponent>()
|
||||
@@ -96,6 +97,7 @@ namespace BBM
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, -1, 3);*/
|
||||
std::srand(std::time(nullptr));
|
||||
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user