-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleCollision.h
58 lines (43 loc) · 1020 Bytes
/
ModuleCollision.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __ModuleCollision_H__
#define __ModuleCollision_H__
#define MAX_COLLIDERS 50
#include "Module.h"
#include "SDL/include/SDL_rect.h"
enum COLLIDER_TYPE
{
COLLIDER_NONE = -1,
COLLIDER_WALL,
COLLIDER_POINT,
COLLIDER_PLAYER,
COLLIDER_MAX
};
struct Collider
{
SDL_Rect rect;
bool to_delete = false;
COLLIDER_TYPE type;
Module* callback = nullptr;
Collider(SDL_Rect rectangle, COLLIDER_TYPE type, Module* callback = nullptr) :
rect(rectangle),
type(type),
callback(callback)
{}
void SetPos(int, int);
bool CheckCollision(const SDL_Rect& r) const;
};
class ModuleCollision : public Module
{
public:
ModuleCollision();
~ModuleCollision();
update_status PreUpdate() override;
update_status Update() override;
bool CleanUp() override;
Collider* AddCollider(SDL_Rect rect, COLLIDER_TYPE type, Module* callback = nullptr);
void DebugDraw();
private:
Collider* colliders[MAX_COLLIDERS];
bool matrix[COLLIDER_MAX][COLLIDER_MAX];
bool debug = false;
};
#endif // __ModuleCollision_H__