-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleCollision.h
87 lines (63 loc) · 1.77 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
81
82
83
84
85
86
87
#ifndef __ModuleCollision_H__
#define __ModuleCollision_H__
#include <list>
#include "Module.h"
class Entity;
// TODO 9: Create a matrix of game specific types of collision for early discard
// Example: lasers should not collide with lasers but should collider with walls
// enemy shots will collide with other enemies ? and against walls ?
enum TypeCollider { PLAYER, FLAG, NPC };
enum CollisionState
{
COLL_IDLE = 0,
COLL_FIRST,
COLL_REPEAT
};
struct Collider
{
SDL_Rect rect = { 0,0,0,0 };
bool to_delete = false;
TypeCollider typeCollider;
Entity* entity = nullptr;
// TODO 10: Add a way to notify other classes that a collision happened
class CListener
{
public:
virtual void OnCollide(Collider* extType, CollisionState state)
{
LOG("Nothing Collide");
}
};
CListener* listener = nullptr;
Collider(SDL_Rect rectangle, TypeCollider typeCollider) : // expand this call if you need to
rect(rectangle), typeCollider(typeCollider)
{}
void SetPos(int x, int y)
{
rect.x = x;
rect.y = y;
}
bool CheckCollision(const SDL_Rect& r) const;
};
class ModuleCollision : public Module
{
public:
ModuleCollision();
~ModuleCollision();
update_status PreUpdate();
update_status Update();
bool CleanUp();
Collider* AddCollider(const SDL_Rect& rect, TypeCollider typeCollider, Collider::CListener* listener, Entity* entity);
void DebugDraw();
private:
std::list<Collider*> colliders;
bool debug = false;
//PLAYER FLAG NPC
bool collisionMatrix[3][3] = { { true, true, true },
{ true, false, true },
{ true, true, true } };
CollisionState collisionStateMatrix[3][3] = { { COLL_IDLE, COLL_IDLE, COLL_IDLE },
{ COLL_IDLE, COLL_IDLE, COLL_IDLE },
{ COLL_IDLE, COLL_IDLE, COLL_IDLE } };
};
#endif // __ModuleCollision_H__