Files
Bomberman/sources/System/Keyboard/KeyboardSystem.cpp
TrueBabyChaise 80e9d674e9 Fix documentation and remove friend keyword
Remove friend keyword and put variables in public instead
Fix documentation where the name of the component is not specified

Co-Authored-By: Benjamin HENRY <44569175+EternalRat@users.noreply.github.com>
2021-05-21 15:11:03 +02:00

41 lines
1.2 KiB
C++

//
// Created by Tom Augier on 2021-05-20.
// Edited by Benjamin Henry on 2021-05-20.
//
#include "KeyboardSystem.hpp"
#include "sources/Component/Keyboard/KeyboardComponent.hpp"
#include "sources/Component/Controllable/ControllableComponent.hpp"
#include "lib/wal/sources/Entity/Entity.hpp"
namespace BBM
{
const std::type_info &KeyboardSystem::getComponent() const
{
return typeid(KeyboardComponent);
}
void KeyboardSystem::onFixedUpdate(WAL::Entity &entity)
{
auto &keyboard = entity.getComponent<KeyboardComponent>();
auto &controllable= entity.getComponent<ControllableComponent>();
static const std::map<int, bool> keyPressedMap = {
{keyboard.keyJump, controllable.jump},
{keyboard.keyBomb, controllable.bomb},
{keyboard.keyPause, controllable.pause}
};
for (auto key : keyPressedMap)
key.second = RAY::IsKeyPressed(key.first);
controllable.moveX = 0;
controllable.moveZ = 0;
if (RAY::IsKeyPressed(keyboard.keyRight))
controllable.moveX += 1;
if (RAY::IsKeyPressed(keyboard.keyLeft))
controllable.moveX -= 1;
if (RAY::IsKeyPressed(keyboard.keyUp))
controllable.moveX += 1;
if (RAY::IsKeyPressed(keyboard.keyDown))
controllable.moveX -= 1;
}
}