31 lines
1.1 KiB
C++
31 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <object/components/component.hpp>
|
|
#include <state/gamestate.hpp>
|
|
#include <unordered_set>
|
|
|
|
namespace Game::Object::Components {
|
|
struct BoxColliderBounds {
|
|
float left, right, top, bottom;
|
|
};
|
|
|
|
class BoxCollider : public Component {
|
|
public:
|
|
BoxCollider() = default;
|
|
BoxCollider(const BoxCollider&);
|
|
BoxCollider& operator=(const BoxCollider&);
|
|
BoxCollider(BoxCollider&&) noexcept;
|
|
BoxCollider& operator=(BoxCollider&&) noexcept;
|
|
~BoxCollider() override;
|
|
|
|
void start(Object::Entity* thisEntity) override;
|
|
void update(float deltaTime, Object::Entity* thisEntity) override;
|
|
|
|
BoxColliderBounds getBounds() const { return mBounds; }
|
|
bool isColliding() const { return !mCollidingWith.empty(); }
|
|
|
|
private:
|
|
BoxColliderBounds mBounds{0.f, 0.f, 0.f, 0.f};
|
|
std::unordered_set<Object::Entity*> mCollidingWith; // Track collisions per-entity so enter/stay/exit callbacks remain correct with multiple colliders
|
|
};
|
|
} |