cs381/as6/components/HazardComponent.cpp

29 lines
727 B
C++

#include "components/HazardComponent.hpp"
#include "Entity.hpp"
#include "components/ColliderComponent.hpp"
void HazardComponent::Setup() {
auto selfCollider = entity->GetComponent<ColliderComponent>();
if (!selfCollider) {
return;
}
selfCollider->get().monitoring = true;
selfCollider->get().AddCollisionListener([this](Entity &other) {
if (!context || !context->probeEntity || &other != context->probeEntity) {
return;
}
// hazards instantly end the run by calling the death callback
if (context->onPlayerDeath) {
context->onPlayerDeath();
}
});
}
void HazardComponent::Update(float) {}
void HazardComponent::Cleanup() {}