-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationManager.cpp
49 lines (46 loc) · 1.29 KB
/
AnimationManager.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
#include "AnimationManager.h"
#include <iostream>
#include <math.h>
using namespace std;
AnimationManager::AnimationManager(int nworms) {
n = nworms;
animators = (WormAnimator *) malloc(n * sizeof(WormAnimator));
for (int i = 0; i < n; i++) {
Worm worm(Coordinate(rand() % (WIDTH-WORM_LENGTH-1) + 1,
rand() % (HEIGHT-1) + 1));
animators[i] = WormAnimator(worm);
}
}
void AnimationManager::paint_frame() {
for (int i = 0; i < n; i++) {
switch (animators[i].get_type()) {
case 0:
animators[i].move_straight();
if (animators[i].get_s_count() == 30) {
animators[i].set_s_count(0);
animators[i].change_type();
}
break;
case 1:
animators[i].move_circular();
if (animators[i].get_c_count() == 50) {
animators[i].set_c_count(0);
animators[i].change_type();
animators[i].change_radio();
}
break;
case 2:
animators[i].move_meandering();
if (animators[i].get_m_count() >= 45) {
animators[i].set_m_count(0);
animators[i].change_type();
animators[i].change_dir_m();
}
break;
default:
break;
}
if (animators[i].touched_border())
animators[i].change_dir();
}
}