-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemyFlying.cpp
44 lines (34 loc) · 1.1 KB
/
EnemyFlying.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
#include "EnemyFlying.hpp"
#define MOVEMENT 80
EnemyFlying::EnemyFlying(){
_hp = 3;
_objective.x = -1;
_objective.y = -1;
init();
}
void EnemyFlying::init(){
_texture = &Resources::enemyStar;
_spawnAnimation = &Resources::spawnAnim;
_destroyAnimation = &Resources::destroyAnim;
}
void EnemyFlying::getNewObjective(){
_objective.x = rand()%1024;
_objective.y = rand()%768;
float mod = (getModule(getPosition(), _objective))+0.0001;
_deltaX = (_objective.x - getPosition().x) /mod;
_deltaY = (_objective.y - getPosition().y) /mod;
}
void EnemyFlying::movement(float deltaTime, Background *bg){
if(_objective.x == -1) getNewObjective();
if(getPosition().x == _objective.x && getPosition().y == _objective.y ){
_objective.x = -1;
}
_vel.x = MOVEMENT*deltaTime*_deltaX;
_vel.y = MOVEMENT*deltaTime*_deltaY;
if(bg->circleColision(sf::Vector2f(getPosition().x + _vel.x,getPosition().y + _vel.y), getGlobalBounds().width/2)){
_objective.x = -1;
}else {
move(_vel.x, _vel.y);
rotate(_vel.x/60.0*180/3.1415);
}
}