mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-01 01:38:14 +00:00
Add basic controls components and system
KeyboardComponents/System + ControllableComponents/ControllableSystem
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#include "ControllableSystem.hpp"
|
||||
#include "lib/wal/sources/Component/Movable/MovableComponent.hpp"
|
||||
#include "sources/Component/Controllable/ControllableComponent.hpp"
|
||||
#include "lib/wal/sources/Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
const std::type_info &ControllableSystem::getComponent() const
|
||||
{
|
||||
return typeid(ControllableComponent);
|
||||
}
|
||||
|
||||
void ControllableSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
auto &controllable= entity.getComponent<ControllableComponent>();
|
||||
auto &movable= entity.getComponent<WAL::MovableComponent>();
|
||||
|
||||
if (controllable._left)
|
||||
movable.addForce(WAL::Vector3f(-1, 0, 0));
|
||||
if (controllable._right)
|
||||
movable.addForce(WAL::Vector3f(1, 0, 0));
|
||||
if (controllable._down)
|
||||
movable.addForce(WAL::Vector3f(0, 0, -1));
|
||||
if (controllable._up)
|
||||
movable.addForce(WAL::Vector3f(0, 0, 1));
|
||||
if (controllable._jump)
|
||||
movable.addForce(WAL::Vector3f(0, 1, 0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Created by Tom Augier on 2021-05-20.
|
||||
// Edited by Benjamin Henry on 2021-05-20.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/wal/sources/System/System.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Controllable entities.
|
||||
class ControllableSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
const std::type_info &getComponent() const override;
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
ControllableSystem() = default;
|
||||
//! @brief A Controllable system is copy constructable
|
||||
ControllableSystem(const ControllableSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~ControllableSystem() override = default;
|
||||
//! @brief A Controllable system is assignable.
|
||||
ControllableSystem &operator=(const ControllableSystem &) = default;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user