The Table Engine
collide.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "component.h"
4 #include "vec2.h"
5 
6 #include "SDL2/SDL.h"
7 
24 class Collide: public Component {
25 private:
26  SDL_Rect* mCollide;
27 
28  float mOffsetX, mOffsetY;
29 
36  SDL_Rect* nextRect(float dx, float dy);
37 
38 public:
42  Collide();
43 
47  ~Collide();
48 
53  SDL_Rect* getRect();
54 
60 
66 
73  void preventCollision(Collide* anotherCollide, float& dx, float& dy);
74 
80  void setTransformOffset(int x, int y);
81 
87  void setScreenPosition(int x, int y);
88 
93  void setScreenPosition(Vec2 pos);
94 
100  void setScreenSize(int w, int h);
101 
106  void setScreenSize(Vec2 size);
107 
113  bool isColliding(SDL_Rect* rect);
114 
120  bool isColliding(Collide* collide);
121 
125  void update();
126 
130  void render();
131 };
Component to handle collisions between game objects.
Definition: collide.h:24
SDL_Rect * mCollide
The collision rectangle relative to the screen.
Definition: collide.h:26
float mOffsetX
Definition: collide.h:28
void preventCollision(Collide *anotherCollide, float &dx, float &dy)
Modifies velocities to prevent collision with another Collide component.
Definition: collide.cpp:35
~Collide()
Destructor for the Collide component.
Definition: collide.cpp:20
void setScreenSize(int w, int h)
Sets the size of the collider on the screen.
Definition: collide.cpp:100
float mOffsetY
Offset of the collider's position from the game object's transform position.
Definition: collide.h:28
void render()
Renders the collision boundaries for debugging purposes.
Definition: collide.cpp:146
void setTransformOffset(int x, int y)
Sets the offset of the collider from the transform's position.
Definition: collide.cpp:88
SDL_Rect * nextRect(float dx, float dy)
Calculates the position of the collider for the next frame.
Definition: collide.cpp:30
void setScreenPosition(int x, int y)
Sets the screen position of the collider.
Definition: collide.cpp:94
Collide()
Constructor for the Collide component.
Definition: collide.cpp:11
Vec2 getScreenSize()
Retrieves the size of the collision rectangle on the screen.
Definition: collide.cpp:83
bool isColliding(SDL_Rect *rect)
Checks if this collider is colliding with a given SDL_Rect.
Definition: collide.cpp:118
Vec2 getScreenPosition()
Retrieves the screen position of the collision rectangle.
Definition: collide.cpp:78
void update()
Updates the collision state of the component.
Definition: collide.cpp:128
SDL_Rect * getRect()
Gets the current collision rectangle.
Definition: collide.cpp:25
Base class for all game components, providing basic component functionalities.
Definition: component.h:25
Defines the Component base class for all components in the game engine.
A structure to represent 2D vectors.
Definition: vec2.h:16
Definition of Vec2 structure for 2D vector operations.