55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "Component.hpp"
|
|
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
/**
|
|
* Distance-based circle collider with event callbacks.
|
|
*
|
|
* `monitoring` enables active overlap checks, similar to Godot's Area2D monitoring.
|
|
* `monitorable` lets this collider be seen by monitors.
|
|
*/
|
|
struct ColliderComponent : public Component {
|
|
/**
|
|
* Radius of the circular collider, used for distance checks against other colliders.
|
|
*/
|
|
float radius = 8.0f;
|
|
|
|
/**
|
|
* Whether this collider actively checks for overlaps and emits collision events.
|
|
*/
|
|
bool monitoring = false;
|
|
|
|
/**
|
|
* Whether this collider can be detected by other colliders that have monitoring enabled.
|
|
*/
|
|
bool monitorable = true;
|
|
|
|
/**
|
|
* Callbacks to invoke when a collision with another entity is detected. The callback
|
|
* receives the other entity involved in the collision.
|
|
*/
|
|
std::vector<std::function<void(Entity &)>> onCollision;
|
|
|
|
void Setup() override;
|
|
|
|
/**
|
|
* Emits a collision event to all registered listeners with the given other entity.
|
|
*
|
|
* @param other The other entity that this collider has collided with.
|
|
*/
|
|
void EmitCollision(Entity &other);
|
|
|
|
/**
|
|
* Registers a collision listener callback to be invoked when a collision is detected.
|
|
*
|
|
* @param callback The callback function that takes the other entity as an argument.
|
|
*/
|
|
void AddCollisionListener(std::function<void(Entity &)> callback);
|
|
|
|
void Update(float dt) override;
|
|
void Cleanup() override;
|
|
};
|