-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleCollisions.h
96 lines (72 loc) · 2 KB
/
ModuleCollisions.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
88
89
90
91
92
93
94
95
96
#pragma once
#ifndef __MODULE_COLLISIONS_H__
#define __MODULE_COLLISIONS_H__
#define MAX_COLLIDERS 50
#include "Module.h"
#include "SDL_Rect.h"
struct Collider
{
enum Type
{
NONE = -1,
WALL,
PLAYER,
ENEMY,
PLAYER_SHOT,
ENEMY_SHOT,
BOSS,
POWERUP_ORANGE,
POWERUP_BLUE,
WEAPON,
WEAPON_SHELL,
MAX
};
//Methods
Collider(SDL_Rect rectangle, Type type, Module* listener = nullptr);
void SetPos(int x, int y);
bool Intersects(const SDL_Rect& r) const;
//Variables
SDL_Rect rect;
bool pendingToDelete = false;
Type type;
Module* listener = nullptr;
};
class ModuleCollisions : public Module
{
public:
// Constructor
// Fills all collision matrix data
ModuleCollisions(bool startEnabled);
// Destructor
~ModuleCollisions();
// Called at the beginning of the application loop
// Removes all colliders pending to delete
// Checks for new collisions and calls its listeners
update_status PreUpdate();
// Called at the middle of the application loop
// Switches the debug mode on/off
update_status Update();
// Called at the end of the application loop
// Draw all colliders (if debug mode is enabled)
update_status PostUpdate();
// Removes all existing colliders
bool CleanUp();
// Adds a new collider to the list
Collider* AddCollider(SDL_Rect rect, Collider::Type type, Module* listener = nullptr);
//Delete collider to the list
bool DeleteCollider(Collider* collider);
// Draws all existing colliders with some transparency
void DebugDraw();
inline uint GetColliderCount() const { return colliderCount; };
private:
// All existing colliders in the scene
Collider* colliders[MAX_COLLIDERS] = { nullptr };
// The collision matrix. Defines the interaction for two collider types
// If set two false, collider 1 will ignore collider 2
bool matrix[Collider::Type::MAX][Collider::Type::MAX];
// Simple debugging flag to draw all colliders
bool debug = false;
// The amount of colliders loaded into the array
uint colliderCount = 0;
};
#endif // __MODULE_COLLISIONS_H__