-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyBullet.cpp
71 lines (47 loc) · 1.56 KB
/
EnemyBullet.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
#include "EnemyBullet.h"
EnemyBullet::EnemyBullet() {
}
EnemyBullet::~EnemyBullet() {
}
void EnemyBullet::loadFromFile(SDL_Renderer *renderer, string path) {
bulletTexture.loadFromFile(renderer, path);
}
void EnemyBullet::render (SDL_Renderer *renderer) {
for (unsigned int i = 0; i < bullets.size(); i++) {
bullets[i].render(renderer, -bullets[i].getAngle());
}
}
void EnemyBullet::moveBullets(double vel, double timeStep) {
for (int i = 0; i < bullets.size(); i++) {
double angle = bullets[i].getAngle() *M_PI / 180;
bullets[i].setX(bullets[i].getX() + vel*cos(angle)* timeStep);
bullets[i].setY(bullets[i].getY() - vel*sin(angle)* timeStep);
if (bullets[i].getY() + GlobalResource::ENEMY_HEIGHT < 0
|| bullets[i].getX() + GlobalResource::BULLET_WIDTH <0
|| bullets[i].getY() > GlobalResource::MAIN_AREA_HEIGHT+GlobalResource::ENEMY_HEIGHT
|| bullets[i].getX() > GlobalResource::MAIN_AREA_WIDTH) {
deleteBullet(i);
}
}
}
void EnemyBullet::createBullet(double mPosX, double x, double mPosY, double y,int vel,double angle) {
Bullet newBullet = Bullet(bulletTexture, mPosX + x , mPosY -y ,vel, angle);
bullets.push_back(newBullet);
}
bool EnemyBullet::isCollision(double centerX, double centerY, int radius) {
for (Bullet bullet : bullets) {
if (bullet.isCollision(centerX, centerY, radius)) {
return true;
}
}
return false;
}
vector<Bullet> EnemyBullet::getBullets() {
return bullets;
}
void EnemyBullet::deleteBullet (int index) {
bullets.erase(bullets.begin() + index);
}
void EnemyBullet::clear() {
bullets.clear();
}