/
enemy.cc
66 lines (52 loc) · 1.04 KB
/
enemy.cc
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
#include "ship.h"
#include "data_structures.h"
#include <math.h>
#include <time.h>
#include "wall.h"
enemy::enemy():ship()
{
side = O_ENEM;
bt = rand()%1000;
image = enemy_image;
nbf = 2;
nbd = 7;
fire_vel = 0.06;
}
void enemy::chv()
{
vy = sin(time(NULL)+bt)*0.01;
}
void enemy::activity()
{
if (rand()%(40-count%20) == 0)
fire();
}
void enemy::on_die()
{
if (eexpl == 0)
return;
for (int i = 0; i < nbd; i++)
{
enemy_bomb *newr = new enemy_bomb;
newr->vx = fire_vel*cos(i*2*3.14159/nbd);
newr->vy = fire_vel*sin(i*2*3.14159/nbd);
newr->x = x+newr->vx*2;
newr->y = y+newr->vy*2;
newr->alpha=i*180/nbd;
ships.push_back(newr);
}
}
void enemy::fire(void)
{
for (int i = 0; i < nbf; i++)
{
double a = alpha + (i-(nbf-1)/2.0)*40*2/(nbf-1);
enemy_bomb *newr = new enemy_bomb;
newr->x = x+0.15*cos(a*3.1415926535/180);
newr->y = y+0.15*sin(a*3.1415926535/180);
newr->vx = fire_vel*cos(a*3.1415926535/180)+vx;
newr->vy = fire_vel*sin(a*3.1415926535/180)+vy;
newr->alpha=180;
ships.push_back(newr);
}
}