-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCollisionSystem.h
More file actions
67 lines (58 loc) · 2.1 KB
/
CollisionSystem.h
File metadata and controls
67 lines (58 loc) · 2.1 KB
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
#ifndef COLLISION_SYSTEM_H
#define COLLISION_SYSTEM_H
#include "raylib.h"
#include <vector>
/**
* @file CollisionSystem.h
* @brief Defines the collision detection system used in the game.
*
* This file includes common collision structures and functions that handle
* collision detection between characters, attacks, and environmental objects.
*/
// Global scale factor for all sprites and collision boxes
const float SPRITE_SCALE = 1.5f;
// Global flag to toggle collision box visibility
extern bool showCollisionBoxes;
/**
* @enum CollisionBoxType
* @brief Defines the different types of collision boxes used in the game.
*/
enum CollisionBoxType {
BODY, ///< Main body collision for movement and general collisions.
ATTACK, ///< Attack hitbox for detecting when attacks hit enemies.
HURTBOX ///< Vulnerable area where the character can be hit.
};
/**
* @struct CollisionBox
* @brief Represents a collision box used for character and attack detection.
*/
struct CollisionBox {
Rectangle rect; ///< The rectangle defining the collision box.
CollisionBoxType type; ///< Type of collision box.
bool active; ///< Whether the collision box is currently active.
/**
* @brief Constructs a CollisionBox.
* @param r The rectangle defining the collision box.
* @param t The type of the collision box (BODY, ATTACK, HURTBOX).
* @param a Whether the collision box is active (default: true).
*/
CollisionBox(Rectangle r, CollisionBoxType t, bool a = true)
: rect(r), type(t), active(a) {}
};
/**
* @brief Checks for a collision between two active collision boxes.
*
* This function determines if two active collision boxes overlap.
* If either box is inactive, it returns false.
*
* @param box1 The first collision box.
* @param box2 The second collision box.
* @return True if the boxes collide, false otherwise.
*/
bool checkCollision(const CollisionBox& box1, const CollisionBox& box2) {
if (box1.active && box2.active) {
return CheckCollisionRecs(box1.rect, box2.rect);
}
return false;
}
#endif // COLLISION_SYSTEM_H