Collider (component)#
Component for defining Entity’s collision information, such as its bounding boxes and collision attributes defined by the collision_handle enumerator.
The shape of the collider can be dynamically updated according to the shape of the Sprite
component,
which must be enabled by calling Collider::enable_dynamic_shape
.
For checking how the collision is actually handled, see Collision
.
Enums
-
enum class CollisionHandle : std::size_t#
Options for collision handling:
CollisionHandle::IMMOVABLE: Cannot move the object.
CollisionHandle::MOVABLE: The object can move by itself.
CollisionHandle::PUSH: The object can be pushed.
CollisionHandle::PHASE: Collision is identified but it is not moved nor does it stops other objects from moving.
CollisionHandle::DESTROY: Destroy the object when any collision happpens (e.g. a projectile that hits a wall).
Values:
-
enumerator IMMOVABLE#
-
enumerator MOVABLE#
-
enumerator PUSH#
-
enumerator PHASE#
-
enumerator DESTROY#
-
enum projectile_handle#
Options for handling collisions against projectiles. Currently unused. Could eventually add the possibility to reflect projectiles.
Actually, this probably won’t be used, this information will probably be integrated into collision_handle.
Values:
-
enumerator INDESTRUCTABLE_ON_PROJECTILE#
-
enumerator DESTROY_ON_PROJECTILE#
-
enumerator DAMAGE_ON_PROJECTILE#
-
enumerator INDESTRUCTABLE_ON_PROJECTILE#
-
struct Collider : public Component#
- #include <Collider.hpp>
Component used for collision detection. Currently only supports AABB collistion (intersecting rectangles).
Public Functions
-
inline Collider()#
-
inline Collider(std::string user_tag, CollisionHandle mHandling, int w = 0, int h = 0)#
-
~Collider()#
-
virtual void render() override#
Update function (called every game tick).
-
inline void enable_dynamic_shape()#
-
inline void disable_dynamic_shape()#
Public Members
-
std::string tag#
This tag could eventually be useful for deciding whether to take the collision into account.
-
bool visualize_collider = false#
-
bool dynamic_shape#
This is only used for debugging. The actual handling is done in the Sprite component with the set_collider attribute. To set it on or off, use the enable_dynamic_shape and disable_dynamic_shape functions. They’ll ensure that dynamic_shape and the Sprite’s set_collider members are in sync.
-
CollisionHandle handling_option#
Information about if the object can move/be moved or not. It should be an entry of the collision_handle enum.
-
std::size_t projectile_handling_option#
Information about if the object should be destroyed or damaged when hit by a projectile.
-
int width#
-
int height#
Width and Height of the rectangular collider.
-
inline Collider()#