-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cpp
47 lines (40 loc) · 894 Bytes
/
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
#include "Bullet.h"
Bullet::Bullet(double xIn, double yIn, double dirXIn, double dirYIn, double speedIn, double damageIn, Manager* pIn)
{
pGame = pIn;
x = xIn;
y = yIn;
dirX = dirXIn;
dirY = dirYIn;
speed = speedIn;
damage = damageIn;
}
bool Bullet::isCollide(double xIn, double yIn)
{
if (distance(x, y, xIn, yIn) < 10)
{
return true;
}
return false;
}
void Bullet::draw_Bullet()
{
pGame->DrawCircle(x, y, 1, olc::YELLOW);
}
void Bullet::bullet_move(float fElapsedTime)
{
x += dirX * speed * fElapsedTime;
y += dirY * speed * fElapsedTime;
}
bool Bullet::erase()
{
if (x < 0 || x > pGame->ScreenWidth() || y < 0 || y > pGame->ScreenHeight())
{
return true;
}
return false;
}
double Bullet::distance(double x1, double y1, double x2, double y2)
{
return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}