-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveEntities.cpp
84 lines (72 loc) · 1.69 KB
/
MoveEntities.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
#include "MoveEntities.h"
MoveEntities::tmpEntity::tmpEntity()
: x(0.0f), y(0.0f), obj() {}
void MoveEntities::add(Entity* p_entity, float p_x, float p_y) {
tmp.obj = p_entity;
tmp.x = p_x;
tmp.y = p_y;
vec.push_back(tmp);
}
void MoveEntities::add(std::vector<Entity*>& eVec, float p_x, float p_y) {
tmp.x = p_x;
tmp.y = p_y;
for (auto& e : eVec) {
tmp.obj = e;
vec.push_back(tmp);
}
}
void MoveEntities::add(std::deque<Entity>& eDeq, float p_x, float p_y) {
tmp.x = p_x;
tmp.y = p_y;
for (auto& e : eDeq) {
tmp.obj = &e;
vec.push_back(tmp);
}
}
void MoveEntities::move() {
for (auto& it : vec) {
it.obj->move(it.x, it.y);
}
}
void MoveEntities::move(std::vector<Entity*>& p_container, float p_x, float p_y) {
for (auto& it : p_container) {
it->move(p_x, p_y);
}
}
void MoveEntities::autoMove(std::vector<Entity*>& p_container) {
int moveOrNot = rand() % 100;
if (moveOrNot == 0) {
int pAxis = rand() % 2;
float autoSpeed = 5.0f;
if (pAxis == 0) {
int leftOrRight = rand() % 2;
if (leftOrRight == 0) {
//playerTwo.setTexture("resources/textures/walt_left.png");
move(p_container, -autoSpeed, 0.0f);
}
else {
//playerTwo.setTexture("resources/textures/walt_right.png");
move(p_container, autoSpeed, 0.0f);
}
}
else {
int leftOrRight = rand() % 2;
if (leftOrRight == 0) {
//playerTwo.setTexture("resources/textures/walt_back.png");
move(p_container, 0.0f, -autoSpeed);
}
else {
//playerTwo.setTexture("resources/textures/walt_front.png");
move(p_container, 0.0f, autoSpeed);
}
}
}
}
bool MoveEntities::empty() {
return (vec.size() == 0);
}
void MoveEntities::clear() {
for (auto& it : vec) {
vec.pop_back();
}
}