mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-03 18:31:17 +00:00
Merge branch 'movements' of github.com:AnonymusRaccoon/Bomberman into movements
This commit is contained in:
@@ -20,6 +20,8 @@ set(SOURCES
|
||||
sources/Component/Movable/MovableComponent.hpp
|
||||
sources/Component/Controllable/ControllableComponent.hpp
|
||||
sources/Component/Controllable/ControllableComponent.cpp
|
||||
sources/Component/Gamepad/GamepadComponent.cpp
|
||||
sources/Component/Gamepad/GamepadComponent.hpp
|
||||
sources/Component/Keyboard/KeyboardComponent.cpp
|
||||
sources/Component/Keyboard/KeyboardComponent.hpp
|
||||
sources/Component/BombHolder/BombHolderComponent.cpp
|
||||
@@ -30,6 +32,8 @@ set(SOURCES
|
||||
sources/System/Movable/MovableSystem.cpp
|
||||
sources/System/Controllable/ControllableSystem.cpp
|
||||
sources/System/Controllable/ControllableSystem.hpp
|
||||
sources/System/Gamepad/GamepadSystem.cpp
|
||||
sources/System/Gamepad/GamepadSystem.hpp
|
||||
sources/System/Health/HealthSystem.cpp
|
||||
sources/System/Health/HealthSystem.hpp
|
||||
sources/System/Keyboard/KeyboardSystem.cpp
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "GamepadComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
GamepadComponent::GamepadComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity), _ID(0)
|
||||
{}
|
||||
|
||||
GamepadComponent::GamepadComponent(WAL::Entity &entity, int ID)
|
||||
: WAL::Component(entity), _ID(ID)
|
||||
{}
|
||||
|
||||
WAL::Component *GamepadComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new GamepadComponent(entity, _ID);
|
||||
}
|
||||
|
||||
GamepadComponent &GamepadComponent::setID(int ID)
|
||||
{
|
||||
this->_ID = ID;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int GamepadComponent::getID() const
|
||||
{
|
||||
return this->_ID;
|
||||
}
|
||||
|
||||
} // namespace BMM
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Controllers/Gamepad.hpp"
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
using Button = RAY::Controller::GamePad::Button;
|
||||
using Gamepad = RAY::Controller::GamePad;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class GamepadComponent : public WAL::Component
|
||||
{
|
||||
private:
|
||||
//! @brief Identifier of the gamepad, used to fetch events
|
||||
int _ID;
|
||||
public:
|
||||
//! @brief jump key
|
||||
Button keyJump = GAMEPAD_BUTTON_RIGHT_FACE_DOWN;
|
||||
//! @brief bomb key
|
||||
Button keyBomb = GAMEPAD_BUTTON_RIGHT_FACE_RIGHT;
|
||||
//! @brief pause key
|
||||
Button keyPause = GAMEPAD_BUTTON_MIDDLE;
|
||||
//! @brief move right key
|
||||
Button keyRight = GAMEPAD_BUTTON_LEFT_FACE_RIGHT;
|
||||
//! @brief move left key
|
||||
Button keyLeft = GAMEPAD_BUTTON_LEFT_FACE_LEFT;
|
||||
//! @brief move up key
|
||||
Button keyUp = GAMEPAD_BUTTON_LEFT_FACE_UP;
|
||||
//! @brief move down key
|
||||
Button keyDown = GAMEPAD_BUTTON_LEFT_FACE_DOWN;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new gampad component using default keys.
|
||||
explicit GamepadComponent(WAL::Entity &entity);
|
||||
|
||||
//! @brief Create a new PositionComponent at a certain position
|
||||
GamepadComponent(WAL::Entity &entity, int id);
|
||||
|
||||
//! @brief A Gamepad component is copy constructable.
|
||||
GamepadComponent(const GamepadComponent &) = default;
|
||||
|
||||
//! @brief default destructor
|
||||
~GamepadComponent() override = default;
|
||||
|
||||
//! @brief A Gamepad component can't be assigned
|
||||
GamepadComponent &operator=(const GamepadComponent &) = delete;
|
||||
|
||||
//! @brief Set the ID of the Gamepad the events must be fetch from;
|
||||
GamepadComponent &setID(int ID);
|
||||
|
||||
//! @brief Get the ID of the Gamepad the events must be fetch from;
|
||||
int getID() const;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "GamepadSystem.hpp"
|
||||
#include "Component/Gamepad/GamepadComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Controllers/Gamepad.hpp"
|
||||
|
||||
using Button = RAY::Controller::GamePad::Button;
|
||||
using Gamepad = RAY::Controller::GamePad;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
GamepadSystem::GamepadSystem()
|
||||
: WAL::System({
|
||||
typeid(GamepadComponent),
|
||||
typeid(ControllableComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void GamepadSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
const auto &gamepadComponent = entity.getComponent<GamepadComponent>();
|
||||
auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
Gamepad gamepad(gamepadComponent.getID());
|
||||
|
||||
const std::map<Button, bool> keyPressedMap = {
|
||||
{gamepadComponent.keyJump, controllable.jump},
|
||||
{gamepadComponent.keyBomb, controllable.bomb},
|
||||
{gamepadComponent.keyPause, controllable.pause}
|
||||
};
|
||||
|
||||
for (auto key : keyPressedMap)
|
||||
key.second = gamepad.isPressed(key.first);
|
||||
controllable.moveX = 0;
|
||||
controllable.moveZ = 0;
|
||||
controllable.moveX += gamepad.isPressed(gamepadComponent.keyRight);
|
||||
controllable.moveX -= gamepad.isPressed(gamepadComponent.keyLeft);
|
||||
controllable.moveX += gamepad.isPressed(gamepadComponent.keyUp);
|
||||
controllable.moveX -= gamepad.isPressed(gamepadComponent.keyDown);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "System/System.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Gamepad entities.
|
||||
class GamepadSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
GamepadSystem();
|
||||
//! @brief A Gamepad system is copy constructable
|
||||
GamepadSystem(const GamepadSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~GamepadSystem() override = default;
|
||||
//! @brief A Gamepad system is assignable.
|
||||
GamepadSystem &operator=(const GamepadSystem &) = default;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user