-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemies.cpp
63 lines (45 loc) · 1.2 KB
/
Enemies.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
#include "Enemies.h"
Enemies::Enemies() {
}
Enemies::~Enemies() {
}
void Enemies::loadFromFile(SDL_Renderer *renderer, string path) {
enemyTexture.loadFromFile(renderer, path);
}
void Enemies::render(SDL_Renderer *renderer) {
for (Enemy enemy : enemies) {
enemy.render(renderer);
}
}
void Enemies::createEnemy(double x, double y, int vel, double angle) {
Enemy enemy(enemyTexture, x, y, vel, angle);
enemies.push_back(enemy);
}
void Enemies::moveEnemy(double stepTime) {
for (unsigned int i = 0; i < enemies.size(); i++ ) {
enemies[i].move(stepTime);
if (enemies[i].getY() + GlobalResource::ENEMY_HEIGHT < 0
|| enemies[i].getX() + GlobalResource::ENEMY_WIDTH <0
|| enemies[i].getY() > GlobalResource::MAIN_AREA_HEIGHT
|| enemies[i].getX() > GlobalResource::MAIN_AREA_WIDTH) {
deleteEnemy(i);
}
}
}
vector<Enemy> Enemies::getEnemies() {
return enemies;
}
void Enemies::deleteEnemy(int index) {
enemies.erase(enemies.begin() + index);
}
bool Enemies::isCollision(double centerX, double centerY, int radius) {
for (Enemy enemy : enemies) {
if (enemy.isCollision(centerX, centerY, radius)) {
return true;
}
}
return false;
}
void Enemies::clear() {
enemies.clear();
}