-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemySmall.cpp
45 lines (40 loc) · 1.64 KB
/
EnemySmall.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
#include "EnemySmall.hpp"
#include "TextureHandler.hpp"
EnemySmall::EnemySmall(Entity &e)
: Enemy(e, 10), _attackDist(0.2)
{
_dir = ((rand() % 2) * 2) - 1;
_dash = false;
e.fixture.radius = 0.03;
e.fixture.mass = 20;
e.renderable.destSize = {e.fixture.radius * 2.1, e.fixture.radius * 2.1};
_maxAnimationFrame = 8;
}
void EnemySmall::attack(Player& player)
{
Vect<2, double> vec(-player.entity.fixture.pos[1], player.entity.fixture.pos[0]);
player.entity.fixture.speed = entity.fixture.speed * 3;
entity.fixture.speed = entity.fixture.speed * -1.5;
_coolDown = 40;
_dash = false;
player.getRekt(1);
}
bool EnemySmall::update(const Player& player)
{
Vect<2, double> vec(-entity.fixture.pos[1], entity.fixture.pos[0]);
Vect<2, double> right(entity.fixture.speed * 0.99 + vec.normalized() * (0.0005 * (6.0 + entity.isOnPlanet)) * -1);
Vect<2, double> left(entity.fixture.speed * 0.99 + vec.normalized() * (0.0005 * (6.0 + entity.isOnPlanet)) * 1);
if (this->Enemy::update(player) && (entity.isOnPlanet || _dash))
{
_dash = true;
entity.fixture.speed = (entity.fixture.speed * 0.99 + vec.normalized() * (0.0005 * (0.05 + entity.isOnPlanet)) * _dir);
if (((right + entity.fixture.pos) - player.entity.fixture.pos).length2() < _attackDist &&
((left + entity.fixture.pos) - player.entity.fixture.pos).length2() > ((right + entity.fixture.pos) - player.entity.fixture.pos).length2())
entity.fixture.speed = right;
else if (((left + entity.fixture.pos) - player.entity.fixture.pos).length2() < _attackDist)
entity.fixture.speed = left;
else
_dash = false;
}
return (false);
}