-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cpp
More file actions
54 lines (44 loc) · 751 Bytes
/
Bullet.cpp
File metadata and controls
54 lines (44 loc) · 751 Bytes
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
#include "Bullet.h"
Bullet::Bullet()
{
mTimer = Timer::Instance();
mSpeed = 1000.0f;
mTexture = new Texture("bullet.png");
mTexture->Parent(this);
mTexture->Pos(VEC2_ZERO);
Reload();
}
Bullet::~Bullet()
{
mTimer = NULL;
delete mTexture;
mTexture = NULL;
}
void Bullet::Fire(Vector2 pos)
{
Pos(pos);
Active(true);
}
void Bullet::Reload()
{
Active(false);
}
void Bullet::Update()
{
if (Active())
{
Translate(-VEC2_UP * mSpeed * mTimer->DeltaTime(), local);
Vector2 pos = Pos();
if (pos.y < -OFFSCREEN_BUFFER || pos.y > Graphics::Instance()->SCREEN_HEIGHT + OFFSCREEN_BUFFER)
{
Reload();
}
}
}
void Bullet::Render()
{
if (Active())
{
mTexture->Render();
}
}