-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModuleCollision.h
73 lines (56 loc) · 1.21 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef __ModuleCollision_H__
#define __ModuleCollision_H__
#define MAX_COLLIDERS 700
#include "Module.h"
enum COLLIDER_TYPE
{
COLLIDER_NONE = -1,
COLLIDER_WALL,
COLLIDER_PLAYER,
COLLIDER_ENEMY,
COLLIDER_PLAYER_SHOT,
COLLIDER_ENEMY_SHOT,
COLLIDER_POWERUP,
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)
{}
COLLIDER_TYPE gettype() { return type; }
void SetPos(int x, int y)
{
rect.x = x;
rect.y = y;
}
bool CheckCollision(const SDL_Rect& r) const;
};
/*
bool operator==(const Collider &o1, const Collider &o2)
{
return o1.gettype() == o2.gettype();
}
*/
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__