-
Notifications
You must be signed in to change notification settings - Fork 2
/
ModuleCollision.h
80 lines (63 loc) · 1.39 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
74
75
76
77
78
79
80
#ifndef __ModuleCollision_H__
#define __ModuleCollision_H__
#define MAX_COLLIDERS 300
#include "Module.h"
#include "SDL\include\SDL.h"
enum COLLIDER_TYPE
{
COLLIDER_NONE = -1,
COLLIDER_WALL,
COLLIDER_PLAYER,
COLLIDER_ENEMY_GROUND,
COLLIDER_ENEMY_AIR,
COLLIDER_PLAYER_SHOT,
COLLIDER_PLAYER2_SHOT,
COLLIDER_PLAYER_BOMB,
COLLIDER_PLAYER2_BOMB,
COLLIDER_ENEMY_SHOT,
COLLIDER_BONUS,
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 x, int y)
{
rect.x = x;
rect.y = y;
}
void SetSize(int w, int h)
{
rect.w = w;
rect.h = h;
}
bool CheckCollision(const SDL_Rect& r) const;
};
class ModuleCollision : public Module
{
public:
ModuleCollision();
~ModuleCollision();
update_status PreUpdate();
update_status Update();
update_status PostUpdate();
bool CleanUp();
Collider* AddCollider(SDL_Rect rect, COLLIDER_TYPE type, Module* callback = nullptr);
bool EraseCollider(Collider* collider);
void SetPosition(Collider * collider, int position_x, int position_y);
void SetSize(Collider * collider, int width, int height);
void DebugDraw();
private:
Collider* colliders[MAX_COLLIDERS];
bool matrix[COLLIDER_MAX][COLLIDER_MAX];
bool debug = false;
};
#endif