-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathECSCustomTypes.hpp
More file actions
163 lines (133 loc) · 3.74 KB
/
ECSCustomTypes.hpp
File metadata and controls
163 lines (133 loc) · 3.74 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** Custom Types
*/
#pragma once
#include <cstddef>
#include <functional>
#include <mutex>
#include <optional>
#include "nlohmann/json.hpp"
extern "C"
{
#include "MessageTypes.h"
}
#include "Registry.hpp"
// all values are in percentage of the screen
namespace Types {
struct CollisionRect {
float width;
float height;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CollisionRect, width, height);
};
struct RectangleShape {
float width;
float height;
};
struct Position {
float x;
float y;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Position, x, y);
};
struct Damage {
int damage;
};
struct Velocity {
float speedX;
float speedY;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Velocity, speedX, speedY);
};
struct SpriteDatas {
SpriteDatas(
const std::string &fileName,
float width,
float height,
std::size_t id,
enum LayerType layer,
std::size_t layerSide)
: fileName(fileName),
width(width),
height(height),
id(id),
layer(layer),
layerSide(layerSide)
{
}
std::string fileName;
float width;
float height;
std::size_t id;
enum LayerType layer;
size_t layerSide;
};
struct Player {
unsigned int constId;
};
struct OtherPlayer {
public:
OtherPlayer(unsigned int id) : constId(id)
{
}
unsigned int constId;
};
struct Missiles {
missileTypes_e type;
};
struct PlayerAllies { };
struct EnemyAllies { };
struct Enemy {
public:
Enemy(enum enemy_type_e _type = enemy_type_e::CLASSIC_ENEMY) : type(_type)
{
std::lock_guard<std::mutex> lock(_mutex);
constId = enemy_id_s {_enemyNb};
_enemyNb++;
}
Enemy(struct enemy_id_s _constId, enum enemy_type_e _type = enemy_type_e::CLASSIC_ENEMY)
: constId(_constId),
type(_type)
{
}
[[nodiscard]] enemy_id_s getConstId() const
{
return constId;
}
static void setEnemyNb(unsigned int nb)
{
std::lock_guard<std::mutex> lock(_mutex);
_enemyNb = nb;
}
static unsigned int getEnemyNb()
{
std::lock_guard<std::mutex> lock(_mutex);
return _enemyNb;
}
enemy_id_s constId;
enum enemy_type_e type;
private:
static unsigned int _enemyNb;
static std::mutex _mutex;
};
struct Parallax {
float x;
float y;
};
struct Dead {
Dead(std::size_t time = 0)
: deathFunction(std::nullopt),
timeToWait(time),
clockId(static_cast<std::size_t>(-1)),
launched(false) {};
Dead(std::optional<std::function<void(std::size_t id)>> func, std::size_t time = 0)
: deathFunction(func),
timeToWait(time),
clockId(static_cast<std::size_t>(-1)),
launched(false) {};
std::optional<std::function<void(std::size_t id)>> deathFunction;
std::size_t timeToWait;
std::size_t clockId;
bool launched;
};
} // namespace Types