-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.cpp
85 lines (57 loc) · 1.4 KB
/
Enemy.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
85
#include "Enemy.h"
Enemy::Enemy(TextureAPI enemyTexture, double x, double y, int vel,double _angle) {
mPosX = x;
mPosY = y;
velocity = vel;
angle = _angle;
hp = 1;
this->enemyTexture = enemyTexture;
}
void Enemy::handleEvent(SDL_Event& e){
}
void Enemy::move(double timeStep) {
mPosX += velocity * timeStep*cos(angle*M_PI / 180);
mPosY -= velocity * timeStep*sin(angle*M_PI / 180);
}
void Enemy::render(SDL_Renderer *renderer) {
enemyTexture.render(renderer, (int)mPosX, (int)mPosY);
}
void Enemy::free() {
enemyTexture.free();
}
void Enemy::createBullet(EnemyBullet &bullets, double x, double y, double angle) {
bullets.createBullet(mPosX+24, x, mPosY+24, y,GlobalResource::ENEMY_BULLET_VEL, angle);
}
void Enemy::setX(double x) {
mPosX = x;
}
void Enemy::setY(double y) {
mPosY = y;
}
double Enemy::getX() {
return mPosX;
}
double Enemy::getY() {
return mPosY;
}
void Enemy::setAngle(double angle) {
this->angle = angle;
}
double Enemy::getAngle() {
return angle;
}
bool Enemy::isCollision(double centerX, double centerY, int radius) {
double d = (centerX - (mPosX + ENEMY_RADIUS))*(centerX - (mPosX + ENEMY_RADIUS)) + (centerY - (mPosY + ENEMY_RADIUS))*(centerY - (mPosY + ENEMY_RADIUS));
if (d > (ENEMY_RADIUS + radius)*(ENEMY_RADIUS + radius)) {
return false;
}
else {
return true;
}
}
int Enemy::getHp() {
return this->hp;
}
void Enemy::setHp(int hp) {
this->hp = hp;
}