42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
#include "components/CollectibleComponent.hpp"
|
|
|
|
#include "Entity.hpp"
|
|
#include "components/AudioComponent.hpp"
|
|
#include "components/ColliderComponent.hpp"
|
|
#include "components/StatsComponent.hpp"
|
|
|
|
void CollectibleComponent::Setup() {
|
|
auto selfCollider = entity->GetComponent<ColliderComponent>();
|
|
if (!selfCollider) {
|
|
return;
|
|
}
|
|
|
|
selfCollider->get().monitoring = true;
|
|
|
|
selfCollider->get().AddCollisionListener([this](Entity &other) {
|
|
if (entity->queuedForFree || !context || !context->probeEntity ||
|
|
&other != context->probeEntity) {
|
|
return;
|
|
}
|
|
|
|
context->EmitCollectiblePicked(*entity);
|
|
entity->QueueFree();
|
|
|
|
if (context->statsEntity) {
|
|
auto stats = context->statsEntity->GetComponent<StatsComponent>();
|
|
if (stats) {
|
|
stats->get().AddValue(stats->get().gainPerStar);
|
|
stats->get().AddStar();
|
|
}
|
|
auto audio = context->statsEntity->GetComponent<AudioComponent>();
|
|
if (audio) {
|
|
audio->get().Play();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void CollectibleComponent::Update(float) {}
|
|
|
|
void CollectibleComponent::Cleanup() {}
|