71 lines
1.5 KiB
C++
71 lines
1.5 KiB
C++
/********************\
|
|
| Copyright 2024, |
|
|
| Ulysse Cura |
|
|
\********************/
|
|
|
|
//////////////////////////////////
|
|
// //
|
|
// Composant pour les portes. //
|
|
// //
|
|
//////////////////////////////////
|
|
|
|
#ifndef DOOR_HPP
|
|
#define DOOR_HPP
|
|
|
|
#include <unordered_map>
|
|
#include "AnimationSystem.hpp"
|
|
#include "ECS.hpp"
|
|
#include "HitboxComponent.hpp"
|
|
|
|
using std::unordered_map;
|
|
|
|
class Door : public Component {
|
|
public:
|
|
Door(unordered_map<int, bool> states) : m_states(states)
|
|
{}
|
|
|
|
void init() override
|
|
{
|
|
m_animation = &entity->getComponent<AnimationSystem>();
|
|
m_hitbox = &entity->getComponent<HitboxComponent>();
|
|
m_animation->loop = false;
|
|
}
|
|
|
|
void update() override
|
|
{
|
|
if(Game::entityManager.getChannelManager().areChannelsInState(m_states))
|
|
{
|
|
if(!m_isDoorOpen)
|
|
{
|
|
m_animation->reverse = false;
|
|
m_animation->playAnimation = true;
|
|
|
|
m_isDoorOpen = true;
|
|
}
|
|
}
|
|
else if(m_isDoorOpen)
|
|
{
|
|
m_animation->reverse = true;
|
|
m_animation->playAnimation = true;
|
|
m_hitbox->hitboxActivated = true;
|
|
|
|
m_isDoorOpen = false;
|
|
}
|
|
|
|
if(!m_animation->playAnimation)
|
|
{
|
|
m_hitbox->hitboxActivated = !m_isDoorOpen;
|
|
}
|
|
}
|
|
|
|
private:
|
|
AnimationSystem *m_animation;
|
|
HitboxComponent *m_hitbox;
|
|
|
|
unordered_map<int, bool> m_states;
|
|
|
|
bool m_isDoorOpen {false};
|
|
};
|
|
|
|
#endif
|