-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulletUpdateComponent.cpp
78 lines (68 loc) · 1.78 KB
/
BulletUpdateComponent.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "BulletUpdateComponent.h"
#include "WorldState.h"
void BulletUpdateComponent::spawnForPlayer(
Vector2f spawnPosition)
{
m_MovingUp = true;
m_BelongsToPlayer = true;
m_IsSpawned = true;
m_TC->getLocation().x = spawnPosition.x;
// Tweak the y location based on the height of the bullet
// The x location is already tweaked to the center of the player
m_TC->getLocation().y = spawnPosition.y - m_TC->getSize().y;
// Update the collider
m_RCC->setOrMoveCollider(m_TC->getLocation().x,
m_TC->getLocation().y,
m_TC->getSize().x, m_TC->getSize().y);
}
void BulletUpdateComponent::spawnForInvader(
Vector2f spawnPosition)
{
m_MovingUp = false;
m_BelongsToPlayer = false;
m_IsSpawned = true;
srand((int)time(0));
m_AlienBulletSpeedModifier = (
((rand() % m_ModifierRandomComponent)))
+ m_MinimumAdditionalModifier;
m_TC->getLocation().x = spawnPosition.x;
// Tweak the y location based on the height of the bullet
// The x location already tweaked to the center of the invader
m_TC->getLocation().y = spawnPosition.y;
// Update the collider
m_RCC->setOrMoveCollider(
m_TC->getLocation().x, m_TC->
getLocation().y, m_TC->getSize().x, m_TC->getSize().y);
}
void BulletUpdateComponent::deSpawn()
{
m_IsSpawned = false;
}
bool BulletUpdateComponent::isMovingUp()
{
return m_MovingUp;
}
void BulletUpdateComponent::update(float fps)
{
if (m_IsSpawned)
{
if (m_MovingUp)
{
m_TC->getLocation().y -= m_Speed * fps;
}
else
{
m_TC->getLocation().y += m_Speed /
m_AlienBulletSpeedModifier * fps;
}
if (m_TC->getLocation().y > WorldState::WORLD_HEIGHT
|| m_TC->getLocation().y < -2)
{
deSpawn();
}
// Update the collider
m_RCC->setOrMoveCollider(m_TC->getLocation().x,
m_TC->getLocation().y,
m_TC->getSize().x, m_TC->getSize().y);
}
}