-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pickup.cpp
69 lines (66 loc) · 1.71 KB
/
Pickup.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
#include "Pickup.h"
#include "TextureHolder.h"
Pickup::Pickup(int type) {
m_Type = type;
if (m_Type == 1) {
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/health_pickup.png"));
m_Value = HEALTH_START_VALUE;
}
else {
m_Sprite = Sprite(TextureHolder::GetTexture("graphics/ammo_pickup.png"));
m_Value = AMMO_START_VALUE;
}
m_Sprite.setOrigin(12, 12);
m_SecondsToLive = START_SECONDS_TO_LIVE;
m_SecondsToWait = START_WAIT_TIME;
}
void Pickup::setArena(IntRect arena) {
m_Arena.left = arena.left + 50;
m_Arena.width = arena.width - 50;
m_Arena.top = arena.top + 50;
m_Arena.height = arena.height - 50;
spawn();
}
void Pickup::spawn() {
srand((int)time(0) / m_Type);
int x = (rand() % m_Arena.width);
srand((int)time(0) * m_Type);
int y = (rand() % m_Arena.height);
m_SecondsSinceSpawn = 0;
m_Spawned = true;
m_Sprite.setPosition(x, y);
}
FloatRect Pickup::getPosition() {
return m_Sprite.getGlobalBounds();
}
Sprite Pickup::getSprite() {
return m_Sprite;
}
bool Pickup::isSpawned() {
return m_Spawned;
}
int Pickup::gotIt() {
m_Spawned = false;
m_SecondsSinceDeSpawn = 0;
return m_Value;
}
void Pickup::update(float elapsedTime) {
if (m_Spawned)
m_SecondsSinceSpawn += elapsedTime;
else
m_SecondsSinceDeSpawn += elapsedTime;
if (m_SecondsSinceSpawn > m_SecondsToLive && m_Spawned) {
m_Spawned = false;
m_SecondsSinceDeSpawn = 0;
}
if (m_SecondsSinceDeSpawn > m_SecondsToWait && !m_Spawned)
spawn();
}
void Pickup::upgrade() {
if (m_Type == 1)
m_Value += (HEALTH_START_VALUE * .5);
else
m_Value += (AMMO_START_VALUE * .5);
m_SecondsToLive += (START_SECONDS_TO_LIVE / 10);
m_SecondsToWait -= (START_WAIT_TIME / 10);
}