-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlock.cpp
42 lines (32 loc) · 941 Bytes
/
Flock.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
#include "Flock.h"
#include <time.h>
Flock::Flock()
{
}
Flock::~Flock()
{
}
void Flock::generate(Dimension windowDimension) {
birds = new Bird*[number_of_birds];
srand(time(NULL));
// Layout birds on the canvas
for (int i = 0; i < number_of_birds; i++) {
birds[i] = new Bird(windowDimension);
float x = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / windowDimension.width));
float y = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / windowDimension.height));
birds[i]->position.x = x - windowDimension.width / 2;
birds[i]->position.y = y - windowDimension.height / 2;
Vector velocityV = Vector();
velocityV.x = rand();
velocityV.y = rand();
velocityV.normalize(birds[i]->MAX_SPEED);
birds[i]->velocity = velocityV;
birds[i]->rotate();
birds[i]->report();
}
}
void Flock::run() {
for (int i = 0; i < number_of_birds; i++) {
birds[i]->run(birds, number_of_birds);
}
}