Nox Engine
 
Loading...
Searching...
No Matches
Collider.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "Constants.h"
9#include "ECS.h"
10#include "Transform.h"
11#include <SDL2/SDL.h>
12#include <functional>
13#include <string>
14
15extern std::vector<Entity*> colliders;
16
22struct Collider : public Component {
23public:
24 std::string tag;
25
37 std::string tag, std::function<void(Collider& other)> onCollision, bool isTrigger = false,
38 bool isStatic = false, bool considerVel = false, bool isUi = false
39 );
44 Collider(std::string tag);
45 ~Collider();
46
50 void init() override;
54 void update() override;
59 void onCollision(Collider& other);
65 const bool isColliding(std::string collTag);
66
67private:
68 SDL_Rect collider;
69 std::function<void(Collider& other)> collFunc;
70 Transform* transform;
71 bool considerVel;
72 bool isTrigger;
73 bool isStatic;
74 bool isUi;
75
76 const bool checkCollision(Collider& other) const;
77 bool AABB(const SDL_Rect& otherRect) const;
78 bool AABB(const Collider& otherColl) const;
79 bool AABBvel(const Collider& otherColl) const;
80};
Defines global constants and enums used throughout the engine and game.
Defines the core classes for the Entity-Component-System (ECS) architecture.
Defines the component for managing an entity's position, rotation, and scale.
Provides an entity with a physical bounding box for collision detection.
Definition Collider.h:22
std::string tag
A tag to identify the type of collider (e.g., "player", "wall").
Definition Collider.h:24
const bool isColliding(std::string collTag)
Checks if this collider is currently colliding with any collider of a specific tag.
Definition Collider.cpp:63
void onCollision(Collider &other)
Executes the collision callback function.
Definition Collider.cpp:59
void update() override
Updates the collider's position and checks for collisions against other colliders.
Definition Collider.cpp:38
void init() override
Initializes the collider by linking it to the entity's transform.
Definition Collider.cpp:29
The base class for all components in the ECS.
Definition ECS.h:53
Stores an entity's position, velocity, scale, and rotation.
Definition Transform.h:17