box collider
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <object/components/component.hpp>
|
||||
#include <state/gamestate.hpp>
|
||||
|
||||
namespace Game::Object::Components {
|
||||
struct BoxColliderBounds {
|
||||
float left, right, top, bottom;
|
||||
};
|
||||
|
||||
class BoxCollider : public Component {
|
||||
public:
|
||||
BoxCollider() = default;
|
||||
@@ -15,6 +20,11 @@ namespace Game::Object::Components {
|
||||
void start(Object::Entity* thisEntity) override;
|
||||
void update(float deltaTime, Object::Entity* thisEntity) override;
|
||||
|
||||
BoxColliderBounds getBounds() const { return mBounds; }
|
||||
bool isColliding() const { return mIsColliding; }
|
||||
|
||||
private:
|
||||
BoxColliderBounds mBounds;
|
||||
bool mIsColliding = false; // Whether this collider is currently colliding with another collider; used to determine whether to call onCollisionEnter vs onCollisionStay, and to call onCollisionExit when collisions end
|
||||
};
|
||||
}
|
||||
@@ -35,6 +35,14 @@ namespace Game::Object {
|
||||
virtual void destroyed() {}; // Pre-destruction call
|
||||
void render(Game::Renderer::Renderer* renderer, Game::Renderer::RendererConfig config);
|
||||
|
||||
// Collision calls
|
||||
// Called once when a collision begins
|
||||
virtual void onCollisionEnter(Entity* other) {}
|
||||
// Called every update while a collision continues
|
||||
virtual void onCollisionStay(Entity* other) {}
|
||||
// Called once when a collision ends
|
||||
virtual void onCollisionExit(Entity* other) {}
|
||||
|
||||
// Setters and getters
|
||||
void setTexture(std::shared_ptr<Game::Renderer::Texture> tex) { mTex = tex; }
|
||||
void setName(const std::string& name) { mName = name; }
|
||||
|
||||
Reference in New Issue
Block a user