-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.h
572 lines (476 loc) · 18.1 KB
/
objects.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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#include <math.h>
#include "paths.h"
#include "background.h"
#pragma once
using namespace sf;
Vector2f norm(Vector2f a);
float getLenght(Vector2f a);
unsigned int maxNumberLeaders = 15;
unsigned int maxLengthName = 20;
unsigned int numberEnemyProduced = 0;
float hard = 1;
int fullBubbles = 100;
int numberBars = 0;
int numberBulletsCage = 50;
int numberBombsCage = 10;
unsigned int speedBullet = 1000;
unsigned int zombieFullHealth = 300;
unsigned int zombie1FullHealth = 1000;
unsigned int zombie2FullHealth = 200;
unsigned int zombie3FullHealth = 200;
unsigned int dogFullHealth = 100;
unsigned int playerFullHealth = 30;
unsigned int playerFullProtection = 200;
unsigned int zombieSpeed = 170;
unsigned int zombie1Speed = 100;
unsigned int zombie2Speed = 150;
unsigned int zombie3Speed = 150;
unsigned int dogSpeed = 180;
unsigned int playerSpeed = 300;
unsigned int zombieDamage = 20;
unsigned int zombie1Damage = 50;
unsigned int zombie2Damage = 10;
unsigned int zombie3Damage = 10;
unsigned int dogDamage = 5;
float speedDrawZombie = 0.05;
float speedDrawZombie1 = 0.1;
float speedDrawZombie2 = 0.2;
float speedDrawZombie3 = 0.2;
float speedDrawDog = 0.1;
float speedDrawPlayer = 0.1;
float timeProducementZombie = 2;
float timeProducementZombie1 = 3;
float timeProducementZombie2 = 5;
float timeProducementZombie3 = 7;
float timeProducementDog = 2.5;
float timeBufferBomb = 0.3;
float timeBombExplore = 1;
float bloodDisappearTime = 0.05;
float timeDissapearItem = 0.1;
//not independent probabilities
float heartProbability = 0.01;
float shieldProbability = 0.02;
float bulletProbability = 0.15;
float bombProbability = 0.1;
float bombDistanceExplode = 100000;
unsigned int pistolDamage = 50;
unsigned int shotgunDamage = 25;
unsigned int bombDamage = 200;
float shotgunAngle = 2.0/180.0*3.1415;
Texture textureBullet1;
Texture textureBullet2;
Texture textureBomb1;
Texture textureBomb2;
Texture textureCursor0;
Texture textureCursor1;
Texture textureHeart;
Texture textureShield;
Texture textureBullet;
Texture textureBomb;
Texture texturePlayerInWater;
Texture textureLocation;
Sprite spritePlayer;
Sprite spriteZombie;
Sprite spriteZombie1;
Sprite spriteZombie2;
Sprite spriteZombie3;
Sprite spriteDog;
Sprite spriteBullet1;
Sprite spriteBullet2;
Sprite spriteBomb1;
Sprite spriteBomb2;
class SortMap{
public:
int key;
std::string string;
};
std::vector <SortMap> leaders;
class Corpse{
public:
Corpse(float angle, Vector2f position, float size){
texture = textureCorpse;
corpse.setTexture(texture);
corpse.setOrigin((float)texture.getSize().x / 2, (float)texture.getSize().y / 2);
corpse.setScale(size/100, size/100);
corpse.setRotation(angle);
corpse.setPosition(position);
timeBuffer = 0;
}
void update(Time time){
timeBuffer += time.asSeconds();
while(timeBuffer > bloodDisappearTime){
timeBuffer -= bloodDisappearTime;
if(corpse.getColor().a > 0)
corpse.setColor(Color(255, 255, 255, corpse.getColor().a - 1));
}
}
bool isDisappeared(){
return corpse.getColor().a <= 0;
}
Sprite corpse;
Texture texture;
float timeBuffer;
};
class Path{
public:
Path(std::vector <Texture> &walkFull,
std::vector <Texture> &walkHalf,
std::vector <Texture> &walkSmall,
int numberwalk, float walktimebuffer,
std::vector <Texture> &attackFull,
std::vector <Texture> &attackHalf,
std::vector <Texture> &attackSmall,
int numberattack, float attacktimebuffer):
PathsWalkFullHealth(walkFull),
PathsWalkHalfHealth(walkHalf),
PathsWalkSmallHealth(walkSmall),
numberWalk(numberwalk),
numberWalkNow(0),
walkTimeBuffer(walktimebuffer),
PathsAttackFullHealth(attackFull),
PathsAttackHalfHealth(attackHalf),
PathsAttackSmallHealth(attackSmall),
numberAttack(numberattack),
numberAttackNow(0),
attackTimeBuffer(attacktimebuffer),
pathIterator(0){};
Path &operator=(const Path &path1){
PathsWalkFullHealth = path1.PathsWalkFullHealth;
PathsWalkHalfHealth = path1.PathsWalkHalfHealth;
PathsWalkSmallHealth = path1.PathsWalkSmallHealth;
numberWalk = path1.numberWalk;
numberWalkNow = path1.numberWalkNow;
walkTimeBuffer = path1.walkTimeBuffer;
PathsAttackFullHealth = path1.PathsAttackFullHealth;
PathsAttackHalfHealth = path1.PathsAttackHalfHealth;
PathsAttackSmallHealth = path1.PathsAttackSmallHealth;
numberAttack = path1.numberAttack;
numberAttackNow = path1.numberAttackNow;
attackTimeBuffer = path1.attackTimeBuffer;
pathIterator = path1.pathIterator;
}
std::vector <Texture> &PathsWalkFullHealth;
std::vector <Texture> &PathsWalkHalfHealth;
std::vector <Texture> &PathsWalkSmallHealth;
int numberWalk;
int numberWalkNow;
float walkTimeBuffer;
std::vector <Texture> &PathsAttackFullHealth;
std::vector <Texture> &PathsAttackHalfHealth;
std::vector <Texture> &PathsAttackSmallHealth;
int numberAttack;
int numberAttackNow;
float attackTimeBuffer;
unsigned int pathIterator;
};
class Organism{
public:
float health;
unsigned int fullHealth;
float protection;
unsigned int speed;
float speedDraw;
int damage;
bool enemy;
Vector2f direction;
Path path;
Sprite organism;
unsigned int uniqueNumber;
int aim;
Organism(
int health1,
int protection1,
unsigned int speed1,
float speedDraw1,
int damage1,
bool enemy1,
std::vector <Texture> &walkFull,
std::vector <Texture> &walkHalf,
std::vector <Texture> &walkSmall,
int numberwalk, float walktimebuffer,
std::vector <Texture> &attackFull,
std::vector <Texture> &attackHalf,
std::vector <Texture> &attackSmall,
int numberattack, float attacktimebuffer,
Sprite &sprite1) :
health(health1),
fullHealth(health1),
protection(protection1),
speed(speed1),
speedDraw(speedDraw1),
damage(damage1),
enemy(enemy1),
direction(Vector2f(0,0)),
path(walkFull,
walkHalf,
walkSmall,
numberwalk,
walktimebuffer,
attackFull,
attackHalf,
attackSmall,
numberattack,
attacktimebuffer),
organism(sprite1),
uniqueNumber(numberEnemyProduced+1){
numberEnemyProduced++;
aim = rand() % 2;
};
~Organism(){};
void attackUpdate(Time time){
// soundsAll.sound[0].play();
path.attackTimeBuffer += time.asSeconds();
if(path.attackTimeBuffer >= speedDraw){
path.attackTimeBuffer -= speedDraw;
path.numberAttackNow = (path.numberAttackNow + 1) % (path.numberAttack);
if(path.pathIterator == 0){
if(this->getPosition().type == 18)
organism.setTexture(path.PathsWalkFullHealth[path.numberWalk]);
else
organism.setTexture(path.PathsAttackFullHealth[path.numberAttackNow]);
} else if(path.pathIterator == 1){
if(this->getPosition().type == 18)
organism.setTexture(path.PathsWalkHalfHealth[path.numberWalk]);
else
organism.setTexture(path.PathsAttackHalfHealth[path.numberAttackNow]);
} else if(path.pathIterator == 2){
if(this->getPosition().type == 18)
organism.setTexture(path.PathsWalkSmallHealth[path.numberWalk]);
else
organism.setTexture(path.PathsAttackSmallHealth[path.numberAttackNow]);
}
}
}
void walkUpdate(Time time){
path.walkTimeBuffer += time.asSeconds();
if(path.walkTimeBuffer >= speedDraw){
path.walkTimeBuffer -= speedDraw;
path.numberWalkNow = (path.numberWalkNow + 1) % (path.numberWalk);
if(path.pathIterator == 0){
if(this->getPosition().type == 18)
organism.setTexture(path.PathsWalkFullHealth[path.numberWalk]);
else
organism.setTexture(path.PathsWalkFullHealth[path.numberWalkNow]);
} else if(path.pathIterator == 1){
if(this->getPosition().type == 18)
organism.setTexture(path.PathsWalkHalfHealth[path.numberWalk]);
else
organism.setTexture(path.PathsWalkHalfHealth[path.numberWalkNow]);
} else if(path.pathIterator == 2){
if(this->getPosition().type == 18)
organism.setTexture(path.PathsWalkSmallHealth[path.numberWalk]);
else
organism.setTexture(path.PathsWalkSmallHealth[path.numberWalkNow]);
}
}
}
void rotate(Vector2f rotateAround){
Vector2f d = rotateAround - organism.getPosition();
organism.setRotation((atan2f(d.y, d.x)*180-270)/M_PI);
}
bool move(Time time){
//player
float len = getLenght(direction);
if(len == 0)
return false;
Vector2f x = Vector2f(direction.x, 0) / len;
Vector2f y = Vector2f(0, direction.y) / len;
if(!enemy){
bool move = false;
//move X
if(this->getNewPosition(speed*time.asSeconds()*x).crossPlayer && x.x != 0){
if(this->getNewPosition(speed*time.asSeconds()*y).crossPlayer && y.y != 0){
organism.move(speed*time.asSeconds() * norm(y + x) * this->getNewPosition(speed*time.asSeconds()*y).speed);
move = true;
} else{
organism.move(speed*time.asSeconds() * norm(x) * this->getNewPosition(speed*time.asSeconds()*x).speed);
move = true;
}
}
//move Y
else if(this->getNewPosition(speed*time.asSeconds()*y).crossPlayer && y.y != 0){
organism.move(speed*time.asSeconds() * norm(y) * this->getNewPosition(speed*time.asSeconds()*y).speed);
move = true;
}
return move;
} else if(enemy){
bool move = false;
//move X
if(this->getNewPosition(speed*time.asSeconds()*x).crossEnemy){
if(this->getNewPosition(speed*time.asSeconds()*y).crossEnemy){
if((x+y).x != 0 || (x+y).y != 0){
organism.move(speed*time.asSeconds() * norm(y + x) * this->getNewPosition(speed*time.asSeconds() * y).speed);
move = true;
}
} else{
if(x.x != 0){
organism.move(speed*time.asSeconds() * norm(x) * this->getNewPosition(speed*time.asSeconds() * x).speed);
move = true;
}
}
}
//move Y
else if(this->getNewPosition(speed*time.asSeconds()*y).crossEnemy){
if(y.y != 0){
organism.move(speed*time.asSeconds() * norm(y) * this->getNewPosition(speed*time.asSeconds() * y).speed);
move = true;
}
}
return move;
} else
return false;
}
bool isInsideOrganism(Organism enemy){
float radiusEnemy = std::min(enemy.organism.getTexture()->getSize().x*enemy.organism.getScale().x*2/5,
enemy.organism.getTexture()->getSize().y*enemy.organism.getScale().y*2/5);
float radiusMy = std::min(organism.getTexture()->getSize().x*organism.getScale().x*2/5,
organism.getTexture()->getSize().y*organism.getScale().y*2/5);
Vector2f d = enemy.organism.getPosition() - organism.getPosition();
return (getLenght(d) < radiusEnemy + radiusMy);
}
Background getPosition(){
return background[(int)(organism.getPosition().x / sizeTile)][(int)(organism.getPosition().y / sizeTile)];
}
Background getNewPosition(Vector2f direct){
return background[(int)((organism.getPosition().x + direct.x) / sizeTile)]
[(int)((organism.getPosition().y + direct.y) / sizeTile)];
}
};
class Feature{
public:
Sprite feature;
int type;
int value;
float timeBuffer;
void update(Time time){
timeBuffer += time.asSeconds();
while(timeBuffer > timeDissapearItem){
timeBuffer -= timeDissapearItem;
if(feature.getColor().a > 0)
feature.setColor(Color(255, 255, 255, feature.getColor().a - 1));
}
}
bool isDisappeared(){
return feature.getColor().a <= 80;
}
bool isInsideOrganism(Organism enemy){
float radius = std::min(enemy.organism.getTexture()->getSize().x, enemy.organism.getTexture()->getSize().y)
*std::min(enemy.organism.getScale().x, enemy.organism.getScale().y);
return (feature.getPosition().x < enemy.organism.getPosition().x + radius)
&& (feature.getPosition().x > enemy.organism.getPosition().x - radius)
&& (feature.getPosition().y > enemy.organism.getPosition().y - radius)
&& (feature.getPosition().y < enemy.organism.getPosition().y + radius);
}
};
class Weapon{
public:
int damage;
float speed;
Vector2f direction;
Sprite weapon;
void rotate(Vector2f rotateAround){
Vector2f d = weapon.getPosition() - rotateAround;
weapon.setRotation((-atan2f(d.x, d.y)*180)/M_PI);
}
bool move(Time time){
Time time1;
if(this->canCross(time) && this->canCross(time1)){
weapon.setPosition(weapon.getPosition() + speed * time.asSeconds() * norm(direction));
return true;
} else
return false;
}
bool isInsideOrganism(Organism enemy){
float radius = std::min(enemy.organism.getTexture()->getSize().x, enemy.organism.getTexture()->getSize().y)/3
*std::min(enemy.organism.getScale().x, enemy.organism.getScale().y);
return (weapon.getPosition().x < enemy.organism.getPosition().x + radius)
&& (weapon.getPosition().x > enemy.organism.getPosition().x - radius)
&& (weapon.getPosition().y > enemy.organism.getPosition().y - radius)
&& (weapon.getPosition().y < enemy.organism.getPosition().y + radius);
}
private:
bool canCross(Time time){
if((weapon.getPosition().x + time.asSeconds()*speed*direction.x > 0) &&
(weapon.getPosition().x + time.asSeconds()*speed*direction.x < sizeWindow.x * sizeTile) &&
(weapon.getPosition().y + time.asSeconds()*speed*direction.y > 0) &&
(weapon.getPosition().y + time.asSeconds()*speed*direction.y < sizeWindow.y * sizeTile)){
return background[(int)((weapon.getPosition().x + time.asSeconds()*speed*direction.x) / sizeTile)]
[(int)((weapon.getPosition().y + time.asSeconds()*speed*direction.x)/ sizeTile)].crossWeapon;
} else
return false;
}
};
class Bomb{
public:
int damage;
Sprite weapon;
int textureNumber;
float timeBuffer;
float timeExplode;
};
class Bar{
public:
Bar(const std::string &str1, const std::string &str2, Color color, float scale){
texture.loadFromFile(str1);
sprite.setTexture(texture);
sprite.setScale(scale, scale);
shape.setFillColor(color);
shape.setSize(Vector2f(190, 20));
font.loadFromFile(str2);
text.setFont(font);
text.setCharacterSize(40);
text.setFillColor(color);
text.setStyle(Text::Bold | Text::Italic);
value = 0;
}
void updateBar(View &gameView, float value, float maxValue){
sprite.setPosition(gameView.getCenter().x + gameView.getSize().x/2 - 200,
gameView.getCenter().y - gameView.getSize().y/2 + 10 + 110*numberBars);
shape.setPosition(sprite.getPosition().x, sprite.getPosition().y + 80);
shape.setScale(value / maxValue, 1);
text.setPosition(sprite.getPosition().x + 80, sprite.getPosition().y + 15);
text.setString(std::to_string((int)(100*value / maxValue)) + "%");
}
void updateBarWeapon(View &gameView, int value, int maxValue){
sprite.setPosition(gameView.getCenter().x + gameView.getSize().x/2 - 200,
gameView.getCenter().y - gameView.getSize().y/2 + 10 + 110*numberBars);
shape.setPosition(sprite.getPosition().x, sprite.getPosition().y + 80);
shape.setScale((value % maxValue) / (float)maxValue, 1);
text.setPosition(sprite.getPosition().x + 80, sprite.getPosition().y + 15);
text.setString(std::to_string((int)(value / maxValue)));
}
Font font;
Text text;
RectangleShape shape;
Texture texture;
Sprite sprite;
float value;
};
class TimeBar{
public:
TimeBar(const std::string &str){
font.loadFromFile(str);
text.setFont(font);
text.setCharacterSize(50);
text.setFillColor(Color(128, 255, 0, 255));
text.setStyle(Text::Bold | Text::Italic);
text.setPosition(0, 0);
}
void update(View &gameView, Time time){
text.setPosition(gameView.getCenter().x - gameView.getSize().x/2 + 20,
gameView.getCenter().y - gameView.getSize().y/2 + 20);
text.setString(std::to_string((int)time.asSeconds()/60) + " min " + std::to_string((int)time.asSeconds() % 60) + " sec");
}
Font font;
Text text;
};
//List of initializations used:
class Strike{
public:
Strike(std::vector<Weapon> &bulletsNew, std::vector<Organism> &enemiesNew, View &view, std::vector<Corpse> &corpse) :
bullets(bulletsNew), enemies(enemiesNew), gameView(view), dead(corpse){};
View &gameView;
std::vector<Weapon> &bullets;
std::vector<Organism> &enemies;
std::vector<Corpse> &dead;
};