-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.h
More file actions
319 lines (231 loc) · 7.8 KB
/
Header.h
File metadata and controls
319 lines (231 loc) · 7.8 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Main.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <time.h>
#include <Windows.h>
#include <algorithm>
#include <string>
using namespace std;
using namespace sf;
class Display
{
public:
void Print(Font font, int size, RenderWindow& window, string str, float x, float y, Color color) {
Text text;
text.setFont(font);
text.setCharacterSize(size);
text.setStyle(Text::Regular);
text.setFillColor(color);
text.setString(str);
text.setPosition(x, y);
window.draw(text);
}
typedef struct DataPrint DataPrint;
private:
string str;
};
//////////////////////////////////////////////// CLASSE WEAPON ////////////////////////////////////////////////
class Weapon
{
public:
int dmgEvryClic; // Le nombre de dégats infligés par clic
int cost; // Le prix de l'arme en question
string img;
string name;
float crit; // Variable qui va définir le pourcentage de coup critique infigés à l'ennemi (entre 0 et 1)
Weapon(int dmg, string name, int cost, float crit, string img);
void CreateSprite(RenderWindow& window, Font font, string img, int nbBoss, float x, float y, float Sx, float Sy, Sprite boss);
string GetWeaponName();
string GetWeaponImg();
int GetWeaponCrit();
private:
};
//Constructeur
Weapon::Weapon(int dmg, string name, int cost, float crit, string img) {
this->dmgEvryClic = dmg;
this->name = name;
this->cost = cost;
this->crit = crit;
this->img = img;
}
string Weapon::GetWeaponName() {
return name;
}
string Weapon::GetWeaponImg() {
return img;
}
int Weapon::GetWeaponCrit() {
return crit;
}
void Weapon::CreateSprite(RenderWindow& window, Font font, string img, int nbWeapon, float x, float y, float Sx, float Sy, Sprite weaponSprite) {
sf::Texture textureWeapon;
if (!textureWeapon.loadFromFile(img)) { // L'img ici c'est la string du nom de l'image qui doit être dans ton dossier comme la font ;)
cout << "Texture : " << img << "loading failed..." << endl; // Message d'erreur dans les logs si une texture ne load pas ^^
system("pause");
}
weaponSprite.setTexture(textureWeapon);
weaponSprite.setPosition(x, y);
weaponSprite.scale(Sx, Sy);
window.draw(weaponSprite);
}
//////////////////////////////////////////////// CLASSE PLAYER ////////////////////////////////////////////////
class Player
{
public:
int money;
int health;
string name;
Weapon* weapon;
Player(int money, int health, string name, Weapon* weapon);
private:
};
//Constructeur
Player::Player(int money, int health, string name, Weapon* weapon) {
this->money = money;
this->health = health;
this->name = name;
this->weapon = weapon;
}
//////////////////////////////////////////////// CLASSE MONSTER ////////////////////////////////////////////////
class Monster
{
public:
int health;
string name;
char abilities;
string image;
Monster(int health, string name, char abilites);
~Monster();
void CreateSprite(RenderWindow& window, Font font, string img, int nbBoss, float x, float y, float Sx, float Sy, Sprite boss); // Comme la fonction print mais avec les sprites
void GettingDamaged(Weapon* weapon, RenderWindow& window, Font font);
private:
};
Monster::Monster(int health, string name, char abilities) {
this->health = health;
this->name = name;
this->abilities = abilities;
}
Monster::~Monster()
{
}
void Monster::GettingDamaged(Weapon* weapon, RenderWindow& window, Font font) {
int probaCrit = rand() % 100; // création de la probabilité d'infliger un coup critique
if (weapon->GetWeaponCrit() * 100 > probaCrit) {
this->health -= weapon->dmgEvryClic * 2; // si le pourcentage est en dessous de celui de l'arme alors les dégats infligés sont multipliés par 2
Display Critical;
string Crit;
Crit = "Crit ! " + to_string(weapon->dmgEvryClic * 2);
float probaAffichageX = rand() % 1000 + 500;
float probaAffichageY = rand() % 500 + 200;
Critical.Print(font, 45, window, Crit, probaAffichageX, probaAffichageY, Color::Red);
}
else {
this->health -= weapon->dmgEvryClic;
Display Critical;
string Crit;
Crit = to_string(weapon->dmgEvryClic);
float probaAffichageX = rand() % 1000 + 500;
float probaAffichageY = rand() % 500 + 200;
Critical.Print(font, 30, window, Crit, probaAffichageX, probaAffichageY, Color::Red);
}
}
// La fameuse fonction avec 100000000 d'arguments xD
void Monster::CreateSprite(RenderWindow& window, Font font, string img, int nbBoss, float x, float y, float Sx, float Sy, Sprite boss) {
sf::Texture texture;
if (!texture.loadFromFile(img)) { // L'img ici c'est la string du nom de l'image qui doit être dans ton dossier comme la font ;)
cout << "Texture : " << img << "loading failed..." << endl; // Message d'erreur dans les logs si une texture ne load pas ^^
system("pause");
}
boss.setTexture(texture);
boss.setPosition(x, y);
boss.scale(Sx, Sy);
window.draw(boss);
}
//////////////////////////////////////////////// DISPLAY & GAME-EVENTS ////////////////////////////////////////////////
class GameEvents
{
public:
void Intro(Font font, RenderWindow& window) {
Display Welcome;
string PWelcome = "Welcome to...";
Welcome.Print(font, 20, window, PWelcome, 800, 500, Color::White);
window.display();
Sleep(2000);
window.clear();
Display Title;
string PTitle = "INFRADVENTURE";
Title.Print(font, 30, window, PTitle, 800, 500, Color::White);
}
void Win(Font font, RenderWindow& window) {
window.clear();
Display Win;
string PWin = "Vous avez gagné face au premier boss !!! Bravo !!!";
Win.Print(font, 20, window, PWin, 800, 500, Color::White);
window.display();
Sleep(2000);
window.clear();
Display End;
string PEnd = "Merci d'avoir joué !!!";
End.Print(font, 20, window, PEnd, 800, 500, Color::White);
window.display();
Sleep(5000);
window.close();
}
private:
};
// J'ai fait une fonction pour le message de resize de la window ;)
void resized(RenderWindow& window, Font font) {
window.clear();
Display warningResize;
string WarnRstr = "Attention ! Vous avez redimentionne la fenetre, cela peut affecter l'affichage de certains elements !";
warningResize.Print(font, 20, window, WarnRstr, 500, 500, Color::White);
window.display();
Sleep(3000);
}
/// <summary>
/// Sert à afficher toutes les informations à l'écran pour le joueur, c'est le HUD (Head Up Display)
/// </summary>
class HUD : public Display // Classe dérivée de Display qui permet d'afficher le HUD
{
public:
void InitHUD(Player* player, Monster* monster, Weapon* weapon, RenderWindow& window, Font font) {
PlayerHealth(player, window, font);
PlayerGold(player, window, font);
MonsterHealth(monster, window, font);
MonsterName(monster, window, font);
WeaponName(weapon, window, font);
}
void PlayerHealth(Player* player, RenderWindow& window, Font font) {
Display HealthPlayer;
string PvPlayer;
PvPlayer = "Vie : " + to_string(player->health);
HealthPlayer.Print(font, 30, window, PvPlayer, 20, 0, Color::Green);
}
void PlayerGold(Player* player, RenderWindow& window, Font font) {
Display GoldPlayer;
string GPlayer;
GPlayer = "Argent : " + to_string(player->health);
GoldPlayer.Print(font, 30, window, GPlayer, 20, 40, Color::Yellow);
}
void MonsterHealth(Monster* monster, RenderWindow& window, Font font) {
Display HealthMonster;
string PvMonster;
PvMonster = to_string(monster->health);
HealthMonster.Print(font, 75, window, PvMonster, 910, 100, Color::Red);
}
void MonsterName(Monster* monster, RenderWindow& window, Font font) {
Display NameMonster;
string NMonster;
NMonster = monster->name;
NameMonster.Print(font, 75, window, NMonster, 800, 800, Color::Red);
}
void WeaponName(Weapon* weapon, RenderWindow& window, Font font) {
Display NameMonster;
string NWeapon;
NWeapon = weapon->name;
NameMonster.Print(font, 25, window, NWeapon, 1640, 990, Color::White);
}
private:
};