-
Notifications
You must be signed in to change notification settings - Fork 15
/
GameFunction.h
1778 lines (1547 loc) · 55.9 KB
/
GameFunction.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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
is::Engine (Infinity Solutions Engine)
Copyright (C) 2018-2024 Is Daouda <isdaouda.n@gmail.com>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GAME_FONCTION_H_INCLUDED
#define GAME_FONCTION_H_INCLUDED
#include <cmath>
#include <ctime>
#include <sstream>
#include <string>
#include <iostream>
#include "../entity/Form.h"
#include "../../../app_src/config/GameConfig.h"
/// Allows to browse object container (std::vector, ...)
#define WITH(_SIZE) for(unsigned int _I = 0; _I < _SIZE; ++_I)
#if defined(__ANDROID__)
// These headers are only needed for direct NDK/JDK interaction
#include <jni.h>
#include <android/native_activity.h>
#include <android/log.h>
#if !defined(IS_ENGINE_SDL_2)
// Since we want to get the native activity from SFML, we'll have to use an
// extra header here:
#include <SFML/System/NativeActivity.hpp>
#endif
#endif
namespace is
{
////////////////////////////////////////////////////////////
// Do not touch these variables unless you know what you are doing
extern const float MAX_CLOCK_TIME; ///< game execution timing variables
extern const float VALUE_CONVERSION; ///< game execution timing variables
extern const float SECOND; ///< represent third value in second
extern const float VALUE_TIME; ///< game execution timing variables
////////////////////////////////////////////////////////////
static const float PI(3.14159f);
////////////////////////////////////////////////////////////
/// \brief SFML Sound or Music state
///
////////////////////////////////////////////////////////////
enum SFMLSndStatus
{
Stopped,
Playing,
Paused
};
/// Convert number to string
template <typename T>
int enumToNum(T val)
{
return static_cast<int>(val);
}
/// Convert wchart_t to string
std::string w_chart_tToStr(wchar_t const *str);
/// Convert string to wstring
std::wstring strToWStr(const std::string &str);
/// Convert number to string
template <typename T>
std::string numToStr(T val)
{
std::ostringstream s;
s << val;
return s.str();
}
/// Convert string to number
template <typename T>
T strToNum(const std::string &str)
{
T val;
std::istringstream iss(str);
iss >> val;
return val;
}
/// Convert number to wstring
template <typename T>
std::wstring numToWStr(T val)
{
std::wostringstream ws;
ws << val;
const std::wstring s(ws.str());
return s;
}
/// Draw zero behind a number
template <typename T>
std::string writeZero(T val, int zeroNumber = 1)
{
std::string str;
for (int i(0); i < zeroNumber; i++)
if (val < std::pow(10, (i + 1))) str += "0";
return (str + is::numToStr(val));
}
/// Return game execution time in millisecond
int getMSecond(const float &DELTA_TIME);
/// Make a tm structure representing this date
std::tm makeTime(int year, int month, int day);
/// Check date limit according to system date
bool checkDateLimit(int year, int mont, int day);
/// Show log message
void showLog(const std::string& str, bool stopApplication = false);
/// Get array size
template <size_t SIZE, class T>
inline size_t arraySize(T (&arr)[SIZE])
{
return SIZE;
}
/// Return a random value
/// \param valNumber Number of values to test
template <typename T>
T choose(unsigned short valNumber, T x1, T x2, T x3 = 0, T x4 = 0, T x5 = 0, T x6 = 0, T x7 = 0, T x8 = 0, T x9 = 0)
{
unsigned int randVal = rand() % valNumber;
switch(randVal)
{
case 1 : return x2; break;
case 2 : return x3; break;
case 3 : return x4; break;
case 4 : return x5; break;
case 5 : return x6; break;
case 6 : return x7; break;
case 7 : return x8; break;
case 8 : return x9; break;
default : break;
}
return x1;
}
/// Return a random value
inline int random(unsigned int limit)
{
return (rand() % limit);
}
/// Set variable limit
template <typename T>
void setVarLimit(T &var, T valMin, T valMax)
{
if (var < valMin) var = valMin;
if (var > valMax) var = valMin;
}
/// Test many values in comparison with a variable
/// \param valNumber number of values to test
bool isIn(unsigned short valNumber, const int var, int x1, int x2, int x3 = 0, int x4 = 0, int x5 = 0, int x6 = 0, int x7 = 0, int x8 = 0, int x9 = 0);
/// Return if a is in [b,c]
bool isBetween(float a, float b, float c);
/// Return if [l1,r1] intersect [l2,r2]
bool isCrossing(float l1, float r1, float l2, float r2);
/// Return sign of x
int sign(float x);
/// Return angle between two points (x1, y1) and (x2, y2)
template <typename T>
T pointDirection(float x1, float y1, float x2, float y2)
{
if (static_cast<int>(x1) == static_cast<int>(x2))
{
if (y2 > y1) return (0.5f * PI);
else return (1.5f * PI);
}
float result = std::atan((y2 - y1) / (x2 - x1));
if (x2 < x1) result += PI;
if (result < 0.f) result += 2.f * PI;
result *= 180.f / PI;
return result;
}
/// Convert radian to grade
float radToDeg(float x);
/// Convert grade to radian
float degToRad(float x);
/// Return x component of the vector
/// \param useScreenScale allows to take into account the scale of the screen during calculations
float lengthDirX(float dir, float angle, bool useScreenScale = false);
/// Return y component of the vector
/// \param useScreenScale allows to take into account the scale of the screen during calculations
float lengthDirY(float dir, float angle, bool useScreenScale = false);
/// Allows to increment a variable while controlling the upper limit
/// \param increaseValue Will be multiplied later by @a is::VALUE_CONVERSION
template <typename T>
void increaseVar(const float &DELTA_TIME, T &var, T increaseValue, T varFinal, T varMax)
{
if (var < varMax) var += ((increaseValue * is::VALUE_CONVERSION) * DELTA_TIME);
else var = varFinal;
}
/// Allows to decrement a variable while controlling the lower limit
/// \param decreasingValue Will be multiplied later by @a is::VALUE_CONVERSION
template <typename T>
void decreaseVar(const float &DELTA_TIME, T &var, T decreaseValue, T varFinal = 0, T varMin = 0)
{
if (var > varMin) var -= ((decreaseValue * is::VALUE_CONVERSION) * DELTA_TIME);
else var = varFinal;
}
/// Test collision between two rectangles
bool collisionTest(Rectangle const &a, Rectangle const &b);
/// Test collision between two circles
bool collisionTest(Circle const &a, Circle const &b);
/// Test collision between rectangle and circle
bool collisionTest(Circle const &circle, Rectangle const &rec);
/// Test collision between rectangle and circle
bool collisionTest(Rectangle const &rec, Circle const &circle);
////////////////////////////////////////////////////////////
// WARNING !!!
// Below this comment all the functions that will be defined
// will be linked to the SFML library.
////////////////////////////////////////////////////////////
/// Return the angle of SFML object
template <class T>
float getSFMLObjAngle(T &obj)
{
return obj.getRotation();
}
/// Return the angle of SFML object
template <class T>
float getSFMLObjAngle(T *obj)
{
return obj->getRotation();
}
/// Return the x scale size of SFML object
template <class T>
float getSFMLObjXScale(T &obj)
{
return obj.getScale().x;
}
/// Return the x scale size of SFML object
template <class T>
float getSFMLObjXScale(T *obj)
{
return obj->getScale().x;
}
/// Return the scale size of SFML object
template <class T>
float getSFMLObjYScale(T &obj)
{
return obj.getScale().y;
}
/// Return the scale size of SFML object
template <class T>
float getSFMLObjYScale(T *obj)
{
return obj->getScale().y;
}
/// Return the width of SFML object
template <class T>
float getSFMLObjWidth(T &obj)
{
return obj.getGlobalBounds().width;
}
/// Return the width of SFML object
template <class T>
float getSFMLObjWidth(T *obj)
{
return obj->getGlobalBounds().width;
}
/// Return the y height of SFML object
template <class T>
float getSFMLObjHeight(T &obj)
{
return obj.getGlobalBounds().height;
}
/// Return the y height of SFML object
template <class T>
float getSFMLObjHeight(T *obj)
{
return obj->getGlobalBounds().height;
}
/// Return the width of SFML texture
inline int getSFMLTextureWidth(sf::Texture const &obj)
{
return obj.getSize().x;
}
/// Return the width of SFML texture
inline int getSFMLTextureWidth(sf::Texture const *obj)
{
return obj->getSize().x;
}
/// Return the height of SFML texture
inline int getSFMLTextureHeight(sf::Texture const &obj)
{
return obj.getSize().y;
}
/// Return the height of SFML texture
inline int getSFMLTextureHeight(sf::Texture const *obj)
{
return obj->getSize().y;
}
/// Return the x origin of SFML object
template <class T>
float getSFMLObjOriginX(T &obj)
{
return obj.getOrigin().x;
}
/// Return the y origin of SFML object
template <class T>
float getSFMLObjOriginY(T &obj)
{
return obj.getOrigin().y;
}
/// Return the x position of SFML object
template <class T>
float getSFMLObjX(T &obj)
{
return obj.getPosition().x;
}
/// Return the x position of SFML object
template <class T>
float getSFMLObjX(T *obj)
{
return obj->getPosition().x;
}
/// Return the y position of SFML object
template <class T>
float getSFMLObjY(T &obj)
{
return obj.getPosition().y;
}
/// Return the y position of SFML object
template <class T>
float getSFMLObjY(T *obj)
{
return obj->getPosition().y;
}
/// Return the alpha of SFML object
template <class T>
unsigned int getSFMLObjAlpha(T &obj)
{
return obj.getColor().a;
}
/// Return the alpha of SFML object
template <class T>
unsigned int getSFMLObjAlpha(T *obj)
{
return obj->getColor().a;
}
/// Set the angle of SFML object
template <class T>
void setSFMLObjAngle(T &obj, float angle)
{
obj.setRotation(angle);
}
/// Set the angle of SFML object
template <class T>
void setSFMLObjAngle(T *obj, float angle)
{
obj->setRotation(angle);
}
/// Set rotation of SFML object
template <class T>
void setSFMLObjRotate(T &obj, float rotationSpeed)
{
obj.rotate(rotationSpeed);
}
/// Set rotation of SFML object
template <class T>
void setSFMLObjRotate(T *obj, float rotationSpeed)
{
obj->rotate(rotationSpeed);
}
/// Set the x scale of SFML object
template <class T>
void setSFMLObjXScale(T &obj, float x)
{
obj.setScale(x, obj.getScale().y);
}
/// Set the x scale of SFML object
template <class T>
void setSFMLObjXScale(T *obj, float x)
{
obj->setScale(x, obj->getScale().y);
}
/// Set the y scale of SFML object
template <class T>
void setSFMLObjYScale(T &obj, float y)
{
obj.setScale(obj.getScale().x, y);
}
/// Set the y scale of SFML object
template <class T>
void setSFMLObjYScale(T *obj, float y)
{
obj->setScale(obj->getScale().x, y);
}
/// Set the x, y scale of SFML object
template <class T>
void setSFMLObjScaleX_Y(T &obj, float x, float y)
{
obj.setScale(x, y);
}
/// Set the x, y scale of SFML object
template <class T>
void setSFMLObjScaleX_Y(T *obj, float x, float y)
{
obj->setScale(x, y);
}
/// Set the scale of SFML object
template <class T>
void setSFMLObjScale(T &obj, float scale)
{
obj.setScale(scale, scale);
}
/// Set the scale of SFML object
template <class T>
void setSFMLObjScale(T *obj, float scale)
{
obj->setScale(scale, scale);
}
/// Set origin of SFML object
template <class T>
void setSFMLObjOrigin(T &obj, float x, float y)
{
obj.setOrigin(x, y);
}
/// Set origin of SFML object
template <class T>
void setSFMLObjOrigin(T *obj, float x, float y)
{
obj->setOrigin(x, y);
}
/// Set x position of SFML object
template <class T>
void setSFMLObjX(T &obj, float x)
{
obj.setPosition(x, obj.getPosition().y);
}
/// Set x position of SFML object
template <class T>
void setSFMLObjX(T *obj, float x)
{
obj->setPosition(x, obj->getPosition().y);
}
/// Set y position of SFML object
template <class T>
void setSFMLObjY(T &obj, float y)
{
obj.setPosition(obj.getPosition().x, y);
}
/// Set y position of SFML object
template <class T>
void setSFMLObjY(T *obj, float y)
{
obj->setPosition(obj->getPosition().x, y);
}
/// Set x, y position of SFML object
template <class T>
void setSFMLObjX_Y(T &obj, float x, float y)
{
obj.setPosition(x, y);
}
/// Set x, y position of SFML object
template <class T>
void setSFMLObjX_Y(T *obj, float x, float y)
{
obj->setPosition(x, y);
}
/// Set x, y position of SFML object
template <class T>
void setSFMLObjX_Y(T &obj, sf::Vector2f position)
{
obj.setPosition(position.x, position.y);
}
/// Set x, y position of SFML object
template <class T>
void setSFMLObjX_Y(T *obj, sf::Vector2f position)
{
obj->setPosition(position.x, position.y);
}
/// Move SFML object on x axis
template <class T>
void moveSFMLObjX(T &obj, float speed)
{
obj.setPosition(obj.getPosition().x + speed, obj.getPosition().y);
}
/// Move SFML object on x axis
template <class T>
void moveSFMLObjX(T *obj, float speed)
{
obj->setPosition(obj->getPosition().x + speed, obj->getPosition().y);
}
/// Move SFML object on y axis
template <class T>
void moveSFMLObjY(T &obj, float speed)
{
obj.setPosition(obj.getPosition().x, obj.getPosition().y + speed);
}
/// Move SFML object on y axis
template <class T>
void moveSFMLObjY(T *obj, float speed)
{
obj->setPosition(obj->getPosition().x, obj->getPosition().y + speed);
}
/// Set SFML object size
template <class T>
void setSFMLObjSize(T &obj, float x, float y)
{
obj.setSize(sf::Vector2f(x, y));
}
/// Set SFML object size
template <class T>
void setSFMLObjSize(T *obj, float x, float y)
{
obj->setSize(sf::Vector2f(x, y));
}
/// Set SFML object size
template <class T>
void setSFMLObjSize(T &obj, sf::Vector2f v)
{
setSFMLObjSize(obj, v.x, v.y);
}
/// Set SFML object size
template <class T>
void setSFMLObjSize(T *obj, sf::Vector2f v)
{
setSFMLObjSize(obj, v.x, v.y);
}
/// Set the alpha of SFML object
template <class T>
void setSFMLObjAlpha(T &obj, unsigned int alpha)
{
obj.setColor(sf::Color(obj.getColor().r, obj.getColor().g, obj.getColor().b, alpha));
}
/// Set the alpha of SFML object
template <class T>
void setSFMLObjAlpha(T *obj, unsigned int alpha)
{
obj->setColor(sf::Color(obj->getColor().r, obj->getColor().g, obj->getColor().b, alpha));
}
/// Set the alpha of SFML shape or text object
template <class T>
void setSFMLObjAlpha2(T &obj, unsigned int alpha)
{
obj.setFillColor(sf::Color(obj.getFillColor().r, obj.getFillColor().g, obj.getFillColor().b, alpha));
}
/// Set the alpha of SFML shape or text object
template <class T>
void setSFMLObjAlpha2(T *obj, unsigned int alpha)
{
obj->setFillColor(sf::Color(obj->getFillColor().r, obj->getFillColor().g, obj->getFillColor().b, alpha));
}
/// Set the alpha and uniform RGB color of SFML object
template <class T>
void setSFMLObjAlpha(T &obj, unsigned int alpha, sf::Uint8 rgb)
{
obj.setColor(sf::Color(rgb, rgb, rgb, alpha));
}
/// Set the alpha and uniform RGB color of SFML object
template <class T>
void setSFMLObjAlpha(T *obj, unsigned int alpha, sf::Uint8 rgb)
{
obj->setColor(sf::Color(rgb, rgb, rgb, alpha));
}
/// Set the alpha and RGB distinct color of SFML object
template <class T>
void setSFMLObjAlpha(T &obj, unsigned int alpha, int r, int g, int b)
{
obj.setColor(sf::Color(r, g, b, alpha));
}
/// Set the alpha and RGB distinct color of SFML object
template <class T>
void setSFMLObjAlpha(T *obj, unsigned int alpha, int r, int g, int b)
{
obj->setColor(sf::Color(r, g, b, alpha));
}
/// Set the color of SFML object
template <class T>
void setSFMLObjColor(T &obj, sf::Color color)
{
obj.setColor(color);
}
/// Set the color of SFML object
template <class T>
void setSFMLObjColor(T *obj, sf::Color color)
{
obj->setColor(color);
}
/// Set the color of SFML shape
template <class T>
void setSFMLObjFillColor(T &obj, sf::Color color)
{
obj.setFillColor(color);
}
/// Set the color of SFML shape
template <class T>
void setSFMLObjFillColor(T *obj, sf::Color color)
{
obj->setFillColor(color);
}
/// Allows to make scale animation
template <class T>
void scaleAnimation(const float &DELTA_TIME, float &var, T &obj, short varSign = 1, float scaleSize = 1.f)
{
if (var > scaleSize) var -= ((0.05f * is::VALUE_CONVERSION) * DELTA_TIME);
else var = scaleSize;
setSFMLObjScale(obj, varSign * var);
}
/// Allows to make scale animation
template <class T>
void scaleAnimation(const float &DELTA_TIME, float &var, T *obj, short varSign = 1, float scaleSize = 1.f)
{
scaleAnimation(DELTA_TIME, var, *obj, varSign, scaleSize);
}
/// Allows to animate SFML text in relation to a option
void setTextAnimation(sf::Text &txt, int &var, int val);
/// Allows to animate SFML text in relation to a option
inline void setTextAnimation(sf::Text *txt, int &var, int val)
{
setTextAnimation(*txt, var, val);
}
/// Allows to animate SFML text and sprites in relation to a option
void setTextAnimation(sf::Text &txt, sf::Sprite &spr, sf::Sprite &sprSelected, int &var, int val);
/// Allows to animate SFML text and sprites in relation to a option
inline void setTextAnimation(sf::Text *txt, sf::Sprite *spr, sf::Sprite *sprSelected, int &var, int val)
{
setTextAnimation(*txt, *spr, *sprSelected, var, val);
}
/// Set the sprite frame with different size (e.g 64x32)
void setFrame(sf::Sprite &sprite, float frame, int subFrame, int frameWidth, int frameHeight, int recWidth, int recHeight);
/// Set the sprite frame with different size (e.g 64x32)
inline void setFrame(sf::Sprite *sprite, float frame, int subFrame, int frameWidth, int frameHeight, int recWidth, int recHeight)
{
setFrame(*sprite, frame, subFrame, frameWidth, frameHeight, recWidth, recHeight);
}
/// Set the sprite frame with the same size (e.g 64x64)
void setFrame(sf::Sprite &sprite, float frame, int subFrame, int frameSize);
/// Set the sprite frame with the same size (e.g 64x64)
inline void setFrame(sf::Sprite *sprite, float frame, int subFrame, int frameSize)
{
setFrame(*sprite, frame, subFrame, frameSize);
}
/// Set the outline thickness and color of SFML object
template <class T>
void setSFMLObjOutlineColor(T &obj, sf::Color color, float thickness = 1.f)
{
obj.setOutlineThickness(thickness);
obj.setOutlineColor(color);
}
/// Set the outline thickness and color of SFML object
template <class T>
void setSFMLObjOutlineColor(T *obj, sf::Color color, float thickness = 1.f)
{
setSFMLObjOutlineColor(*obj, color, thickness);
}
/// Set Texture Rec of SFML object
template <class T>
void setSFMLObjTexRec(T &obj, int x, int y, int w, int h)
{
obj.setTextureRect(sf::IntRect(x, y, w, h));
}
/// Set Texture Rec of SFML object
template <class T>
void setSFMLObjTexRec(T *obj, int x, int y, int w, int h)
{
obj->setTextureRect(sf::IntRect(x, y, w, h));
}
/// Set the properties of SFML Sprite
inline void setSFMLObjProperties(sf::Sprite &obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
is::setSFMLObjAlpha(obj, alpha);
is::setSFMLObjAngle(obj, angle);
is::setSFMLObjScaleX_Y(obj, xScale, yScale);
is::setSFMLObjX_Y(obj, x, y);
}
/// Set the properties of SFML Sprite
inline void setSFMLObjProperties(sf::Sprite *obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
setSFMLObjProperties(*obj, x, y, angle, alpha, xScale, yScale);
}
/// Set the properties of SFML Text
inline void setSFMLObjProperties(sf::Text &obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
is::setSFMLObjAlpha2(obj, alpha);
is::setSFMLObjAngle(obj, angle);
is::setSFMLObjScaleX_Y(obj, xScale, yScale);
is::setSFMLObjX_Y(obj, x, y);
}
/// Set the properties of SFML Text
inline void setSFMLObjProperties(sf::Text *obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
setSFMLObjProperties(*obj, x, y, angle, alpha, xScale, yScale);
}
/// Set the properties of SFML Rectangle
inline void setSFMLObjProperties(sf::RectangleShape &obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
is::setSFMLObjAlpha2(obj, alpha);
is::setSFMLObjAngle(obj, angle);
is::setSFMLObjScaleX_Y(obj, xScale, yScale);
is::setSFMLObjX_Y(obj, x, y);
}
/// Set the properties of SFML Rectangle
inline void setSFMLObjProperties(sf::RectangleShape *obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
setSFMLObjProperties(*obj, x, y, angle, alpha, xScale, yScale);
}
/// Set the properties of SFML Circle
inline void setSFMLObjProperties(sf::CircleShape &obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
is::setSFMLObjAlpha2(obj, alpha);
is::setSFMLObjAngle(obj, angle);
is::setSFMLObjScaleX_Y(obj, xScale, yScale);
is::setSFMLObjX_Y(obj, x, y);
}
/// Set the properties of SFML Circle
inline void setSFMLObjProperties(sf::CircleShape *obj, float x, float y, float angle = 0.f, int alpha = 255, float xScale = 1.f, float yScale = 1.f)
{
setSFMLObjProperties(*obj, x, y, angle, alpha, xScale, yScale);
}
/// Center SFML object
template <class T>
void centerSFMLObj(T &obj)
{
obj.setOrigin(
#if !defined(IS_ENGINE_SFML)
obj.getTextureRect().width / 2, obj.getTextureRect().height / 2
#else
obj.getGlobalBounds().width / 2, obj.getGlobalBounds().height / 2
#endif
);
}
/// Center SFML object
template <class T>
void centerSFMLObj(T *obj)
{
centerSFMLObj(*obj);
}
/// Center SFML object X
template <class T>
void centerSFMLObjX(T &obj)
{
obj.setOrigin(
#if !defined(IS_ENGINE_SFML)
obj.getTextureRect().width / 2
#else
obj.getGlobalBounds().width / 2
#endif
, obj.getOrigin().y);
}
/// Center SFML object X
template <class T>
void centerSFMLObjX(T *obj)
{
centerSFMLObjX(*obj);
}
/// Center SFML object Y
template <class T>
void centerSFMLObjY(T &obj)
{
obj.setOrigin(obj.getOrigin().x,
#if !defined(IS_ENGINE_SFML)
obj.getTextureRect().height / 2
#else
obj.getGlobalBounds().height / 2
#endif
);
}
/// Center SFML object Y
template <class T>
void centerSFMLObjY(T *obj)
{
centerSFMLObjY(*obj);
}
/// Load SFML Texture Resource
inline void loadSFMLTexture(sf::Texture &obj, const std::string& filePath)
{
obj.loadFromFile(filePath);
}
/// Load SFML Texture Resource
inline void loadSFMLTexture(sf::Texture *obj, const std::string& filePath)
{
obj->loadFromFile(filePath);
}
/// Load SFML Font Resource
inline void loadSFMLFont(sf::Font &obj, const std::string& filePath, int fontDefaultSize = is::GameConfig::DEFAULT_SFML_TEXT_SIZE)
{
#if !defined(IS_ENGINE_SFML)
obj.setSDLFontSize(fontDefaultSize);
#endif
obj.loadFromFile(filePath);
}
/// Load SFML Font Resource
inline void loadSFMLFont(sf::Font *obj, const std::string& filePath, int fontDefaultSize = is::GameConfig::DEFAULT_SFML_TEXT_SIZE)
{
loadSFMLFont(*obj, filePath, fontDefaultSize);
}
/// Load SFML Sound Buffer Resource
inline void loadSFMLSoundBuffer(sf::SoundBuffer &obj, const std::string& filePath)
{
obj.loadFromFile(filePath);
}
/// Load SFML Sound Buffer Resource
inline void loadSFMLSoundBuffer(sf::SoundBuffer *obj, const std::string& filePath)
{
obj->loadFromFile(filePath);
}
/// Load SFML Sound Buffer Resource and define it with the Sound
inline void loadSFMLSoundBufferWithSnd(sf::SoundBuffer &sb, sf::Sound &snd, const std::string& filePath)
{
if (sb.loadFromFile(filePath)) snd.setBuffer(sb);
else showLog("ERROR: Can't load Sound Buffer : " + filePath + " with sound");
}
/// Load SFML Sound Buffer Resource and define it with the Sound
inline void loadSFMLSoundBufferWithSnd(sf::SoundBuffer *sb, sf::Sound *snd, const std::string& filePath)
{
loadSFMLSoundBufferWithSnd(*sb, *snd, filePath);
}
/// Load SFML Music Resource
inline void loadSFMLMusic(sf::Music &obj, const std::string& filePath)
{
obj.openFromFile(filePath);
}
/// Load SFML Music Resource
inline void loadSFMLMusic(sf::Music *obj, const std::string& filePath)
{
obj->openFromFile(filePath);
}
/// Check SFML Sound state
template <class T>
bool checkSFMLSndState(T &obj, SFMLSndStatus state)
{
switch (state)
{
case SFMLSndStatus::Playing:
return (obj.getStatus() == sf::Sound::Status::Playing);
break;
case SFMLSndStatus::Stopped:
return (obj.getStatus() == sf::Sound::Status::Stopped);
break;
case SFMLSndStatus::Paused:
return (obj.getStatus() == sf::Sound::Status::Paused);
break;
}
return false;
}
/// Check SFML Sound state
template <class T>
bool checkSFMLSndState(T *obj, SFMLSndStatus state) {
if (obj != nullptr)
{
switch (state)
{
case SFMLSndStatus::Playing:
return (obj->getStatus() == sf::Sound::Status::Playing);
case SFMLSndStatus::Stopped:
return (obj->getStatus() == sf::Sound::Status::Stopped);
case SFMLSndStatus::Paused:
return (obj->getStatus() == sf::Sound::Status::Paused);