Defines the collider system for collision detection. More...
#include <SDL.h>#include <stdbool.h>Go to the source code of this file.
Classes | |
| struct | Collider |
| This struct represents a collider. More... | |
| struct | ColliderCheckResult |
Macros | |
| #define | MAX_COLLISIONS_PER_CHECK 20 |
| #define | MAX_COLLIDABLES 1024 |
Typedefs | |
| typedef struct Collider | Collider |
| This struct represents a collider. | |
| typedef struct ColliderCheckResult | ColliderCheckResult |
Enumerations | |
| enum | CollisionLayer { COLLISION_LAYER_NONE = 0 , COLLISION_LAYER_PLAYER = 1 << 0 , COLLISION_LAYER_ENVIRONMENT = 1 << 1 , COLLISION_LAYER_ENEMY = 1 << 2 , COLLISION_LAYER_TRIGGER = 1 << 3 , COLLISION_LAYER_ENEMY_PROJECTILE = 1 << 4 , COLLISION_LAYER_PLAYER_PROJECTILE = 1 << 5 } |
Functions | |
| void | Collider_Start () |
| Initialize the collision manager. | |
| void | Collider_Register (Collider *collidable, void *owner) |
| Register a collider with the collision manager. | |
| bool | Collider_Check (Collider *collidableObject, ColliderCheckResult *result) |
| Check for collisions with a collider. | |
| void | Collider_Reset (Collider *collider) |
| Deactivates a collider. | |
Variables | |
| Collider * | ColliderList [MAX_COLLIDABLES] |
| int | ColliderCount |
Defines the collider system for collision detection.
This file contains the declarations for the collision manager. The collision manager is responsible for detecting collisions between entities in the game.
TLDR: Create Collider struct somewhere, register it, check for collisions, and handle the collisions.
Note: the collider needs to be stored in a memory that's reusable. (i.e static/global variables)
This collider will check for collision with environment and enemies.
Register the collider with the collision manager:
This will add the collider to the list of colliders that the collision manager checks.
Check for collisions with the collider:
This will check for collisions with the collider and store the results in the result struct. After that, you can do something with the detected collisions:
| #define MAX_COLLIDABLES 1024 |
| #define MAX_COLLISIONS_PER_CHECK 20 |
This struct represents a collider.
A collider is a hitbox that can be used to detect collisions between objects. It is used to detect collisions between entities in the game.
| typedef struct ColliderCheckResult ColliderCheckResult |
| enum CollisionLayer |
| bool Collider_Check | ( | Collider * | collider, |
| ColliderCheckResult * | checkResult | ||
| ) |
Check for collisions with a collider.
| collidableObject | The collider to check |
| result | Where to store the collision results |
Check for collisions with a collider.
This function checks for collision between a collider and everything else in the ColliderList array. Any colliders whose layer is not in the input collider's collidesWith section will be ignored.
| collider | The input collider |
| checkResult | The checkResult of the collider, which includes 2 members: checkResult.objects: an array of detected colliders checkResult.count: number of collisions detected |
| void Collider_Register | ( | Collider * | collider, |
| void * | owner | ||
| ) |
Register a collider with the collision manager.
| collidable | The collider to register |
| owner | The entity that owns this collider |
Register a collider with the collision manager.
This is so that every colliders can be checked by each other.
| collider | A pointer to the collider struct. For example: &player.state.collider |
| owner | A pointer to the owner of the collider. For example: &player |
| void Collider_Reset | ( | Collider * | collider | ) |
Deactivates a collider.
| collider | The collider to deactivate |
Deactivates a collider.
| collider | The collider to reset |
| void Collider_Start | ( | ) |
Initialize the collision manager.
Initialize the collision manager.
|
extern |
|
extern |