-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
61 lines (56 loc) · 1.08 KB
/
bullet.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
#include "bullet.h"
#include "creature.h"
#include <math.h>
Bullet::Bullet(float _speed, int _width, int _height,int _damage, float _aimX, float _aimY, float _startX, float _startY, int _range)
:Mobile(_speed,_width,_height)
{
Damage=_damage;
AimX=_aimX;
AimY=_aimY;
StartX=_startX;
X=_startX;
StartY=_startY;
Y=_startY;
BulletRange=_range;
Angle=calculateAngle(AimX,AimY,StartX,StartY);
}
Bullet::~Bullet()
{
}
void Bullet::reduceHp(Creature* _creature)
{
_creature->setHp(_creature->getHp()-Damage);
}
float Bullet::calculateAngle(float _aimX, float _aimY, float _startX, float _startY)
{
float x=_aimX-_startX;
float y=_aimY-_startY;
if(x==0)
{
if(y>=0)
{
return M_PI/2;
}
else
{
return 3*M_PI/2;
}
}
else
{
float angle=atan(y/x);
if(x>0)
{
return angle;
}
else
{
return angle+M_PI;
}
}
}
void Bullet::move(Board *_map)
{
X+=cos(Angle)*Speed;
Y+=sin(Angle)*Speed;
}