This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BestioleKamikaze.cpp
92 lines (80 loc) · 3.11 KB
/
BestioleKamikaze.cpp
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
#include "BestioleKamikaze.h"
#include <cmath>
double highValue = 300000;
double cibleX = 0;
double cibleY = 0;
double deltaX = 1;
double deltaY = 1;
double distanceCarre = 0;
BestioleKamikaze::BestioleKamikaze(void){}
// Fonction : BestioleKamikaze
// Entrée : les attributs de la bestiole
// Action : Constructeur de la bestiole
BestioleKamikaze::BestioleKamikaze(bool pM, double t, int a, double champo, double disto, double distOr, double capaOeil, double capaOreille, double coeffCamou, double coeffCarap, double coeffDebuffCarap, double coeffNag){
identite = ++next;
cout << "Naissance Bestiole (" << identite << ") " << endl;
x = y = 0;
cumulX = cumulY = 0.;
orientation = static_cast<double>( rand() )/RAND_MAX*2.*M_PI;
vitesse = static_cast<double>( rand() )/RAND_MAX*MAX_VITESSE * (coeffNageoire / coeffDebuffCarapace);
couleur = new T[ 3 ];
couleur[ 0 ] = static_cast<int>( static_cast<double>( rand() )/RAND_MAX*230. );
couleur[ 1 ] = static_cast<int>( static_cast<double>( rand() )/RAND_MAX*230. );
couleur[ 2 ] = static_cast<int>( static_cast<double>( rand() )/RAND_MAX*230. );
persoMult = pM;
taille = t;
anneesRestantes = a;
champOeil = champo;
champOreille = 2*M_PI;
distanceOeil = disto;
distanceOreille = distOr;
capaciteOeil = capaOeil;
capaciteOreille = capaOreille;
coeffCamouflage = coeffCamou;
coeffCarapace = coeffCarap;
coeffDebuffCarapace = coeffDebuffCarap;
coeffNageoire = coeffNag;
}
BestioleKamikaze::~BestioleKamikaze(){};
// Fonction update
// Entrée : listes des bestioles
// Sortie : rien
// Actions : détermine quelle est la bestiole la plus proche de la
// bestiole courante. Actualise l'orientation de la bestiole
// bestiole courante pour qu'elle se dirige vers la bestiole
// la plus proche.
void BestioleKamikaze::update(vector<std::shared_ptr<Bestiole>> & vectorBestioleProche){
if (vectorBestioleProche.size() > 0){
double meilleureDistanceCarre = highValue;
for ( std::vector<std::shared_ptr<Bestiole>>::iterator it1 = vectorBestioleProche.begin();
it1 != vectorBestioleProche.end() ; it1++ ){
deltaX = (**it1).getX() - x;
deltaY = (**it1).getY() - y;
distanceCarre = deltaX*deltaX + deltaY*deltaY;
if (distanceCarre < meilleureDistanceCarre){
meilleureDistanceCarre = distanceCarre;
cibleX = (**it1).getX();
cibleY = (**it1).getY();
}
}
deltaX = cibleX - x;
deltaY = cibleY - y;
if (deltaX == 0) {
if (deltaY >= 0) {
orientation = M_PI / 2;
}
else
{
orientation = -M_PI / 2;
}
}
else if (deltaX < 0) {
orientation = M_PI + atan(deltaY / deltaX);
}
else if (deltaY >= 0) {
orientation = atan(deltaY / deltaX);
} else {
orientation = atan(deltaY / deltaX) + 2*M_PI;
}
}
}