The Table Engine
|
Component to handle collisions between game objects. More...
#include <collide.h>
Public Member Functions | |
Collide () | |
Constructor for the Collide component. More... | |
~Collide () | |
Destructor for the Collide component. More... | |
SDL_Rect * | getRect () |
Gets the current collision rectangle. More... | |
Vec2 | getScreenPosition () |
Retrieves the screen position of the collision rectangle. More... | |
Vec2 | getScreenSize () |
Retrieves the size of the collision rectangle on the screen. More... | |
void | preventCollision (Collide *anotherCollide, float &dx, float &dy) |
Modifies velocities to prevent collision with another Collide component. More... | |
void | setTransformOffset (int x, int y) |
Sets the offset of the collider from the transform's position. More... | |
void | setScreenPosition (int x, int y) |
Sets the screen position of the collider. More... | |
void | setScreenPosition (Vec2 pos) |
Sets the screen position of the collider using a Vec2 object. More... | |
void | setScreenSize (int w, int h) |
Sets the size of the collider on the screen. More... | |
void | setScreenSize (Vec2 size) |
Sets the size of the collider on the screen using a Vec2 object. More... | |
bool | isColliding (SDL_Rect *rect) |
Checks if this collider is colliding with a given SDL_Rect. More... | |
bool | isColliding (Collide *collide) |
Checks if this collider is colliding with another Collide component. More... | |
void | update () |
Updates the collision state of the component. More... | |
void | render () |
Renders the collision boundaries for debugging purposes. More... | |
![]() | |
Component () | |
Default constructor for the Component. More... | |
Component (std::string name) | |
Constructs a Component with a specified name. More... | |
virtual | ~Component () |
Virtual destructor for safe polymorphic use. More... | |
std::string | getName () |
Retrieves the name of the component. More... | |
GameObject * | getOwner () |
Retrieves the GameObject that owns this component. More... | |
void | setName (std::string name) |
Sets the name of the component. More... | |
void | setOwner (GameObject *owner) |
Sets the GameObject owner of this component. More... | |
virtual void | input () |
Virtual method for handling input, intended to be overridden by derived components. More... | |
Private Member Functions | |
SDL_Rect * | nextRect (float dx, float dy) |
Calculates the position of the collider for the next frame. More... | |
Private Attributes | |
SDL_Rect * | mCollide |
The collision rectangle relative to the screen. More... | |
float | mOffsetX |
float | mOffsetY |
Offset of the collider's position from the game object's transform position. More... | |
Additional Inherited Members | |
![]() | |
std::string | m_name |
Name of the component, useful for identification or debugging. More... | |
GameObject * | m_owner |
Pointer to the GameObject that owns this component. More... | |
Component to handle collisions between game objects.
Collide uses SDL_Rect structures to define bounding boxes for collision detection and response. It integrates with the game object's position and allows dynamic adjustment of the collision box based on the game object's movements and interactions.
Collide::Collide | ( | ) |
Constructor for the Collide component.
Definition at line 11 of file collide.cpp.
Collide::~Collide | ( | ) |
Destructor for the Collide component.
Definition at line 20 of file collide.cpp.
SDL_Rect * Collide::getRect | ( | ) |
Gets the current collision rectangle.
Definition at line 25 of file collide.cpp.
Vec2 Collide::getScreenPosition | ( | ) |
Retrieves the screen position of the collision rectangle.
Definition at line 78 of file collide.cpp.
Vec2 Collide::getScreenSize | ( | ) |
Retrieves the size of the collision rectangle on the screen.
Definition at line 83 of file collide.cpp.
bool Collide::isColliding | ( | Collide * | collide | ) |
Checks if this collider is colliding with another Collide component.
collide | Pointer to another Collide component to check against. |
Definition at line 123 of file collide.cpp.
bool Collide::isColliding | ( | SDL_Rect * | rect | ) |
Checks if this collider is colliding with a given SDL_Rect.
rect | Pointer to an SDL_Rect to check against. |
Definition at line 118 of file collide.cpp.
|
private |
Calculates the position of the collider for the next frame.
dx | Horizontal displacement. |
dy | Vertical displacement. |
Definition at line 30 of file collide.cpp.
void Collide::preventCollision | ( | Collide * | anotherCollide, |
float & | dx, | ||
float & | dy | ||
) |
Modifies velocities to prevent collision with another Collide component.
anotherCollide | Pointer to another Collide component. |
dx | Reference to the horizontal velocity that may be modified. |
dy | Reference to the vertical velocity that may be modified. |
Definition at line 35 of file collide.cpp.
|
virtual |
Renders the collision boundaries for debugging purposes.
Reimplemented from Component.
Definition at line 146 of file collide.cpp.
void Collide::setScreenPosition | ( | int | x, |
int | y | ||
) |
Sets the screen position of the collider.
x | Horizontal screen position. |
y | Vertical screen position. |
Definition at line 94 of file collide.cpp.
void Collide::setScreenPosition | ( | Vec2 | pos | ) |
Sets the screen position of the collider using a Vec2 object.
pos | Vec2 object representing the new position. |
Definition at line 106 of file collide.cpp.
void Collide::setScreenSize | ( | int | w, |
int | h | ||
) |
Sets the size of the collider on the screen.
w | Width of the collider. |
h | Height of the collider. |
Definition at line 100 of file collide.cpp.
void Collide::setScreenSize | ( | Vec2 | size | ) |
Sets the size of the collider on the screen using a Vec2 object.
size | Vec2 object representing the new size. |
Definition at line 112 of file collide.cpp.
void Collide::setTransformOffset | ( | int | x, |
int | y | ||
) |
Sets the offset of the collider from the transform's position.
x | Horizontal offset. |
y | Vertical offset. |
Definition at line 88 of file collide.cpp.
|
virtual |
Updates the collision state of the component.
Reimplemented from Component.
Definition at line 128 of file collide.cpp.
|
private |
|
private |