-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPillarManager.cpp
117 lines (96 loc) · 3.12 KB
/
PillarManager.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "PillarManager.h"
PillarManager::PillarManager( const Primitives& primitives, glm::vec3 iPosition ) {
for( int i = 0; i < Globals::PILLAR_COUNT; ++i ) {
this->pillars.push_back(
new Pillar(
primitives,
iPosition
)
);
}
this->Reset();
}
void PillarManager::Update() {
time( &this->timer );
// std::cout << "\nPillar Queue size: " << this->queue.size();
if(
difftime( this->timer, this->startTime ) >=
Globals::PILLAR_SPAWN_TIME
) {
if( !this->queue.empty() ) {
this->pillars[this->queue.front()]->Spawn();
this->pillars[this->queue.front()]->IsInQueue = false;
this->queue.pop();
time( &this->startTime );
//this->IncreaseVelocity();
}
}
for( int i = 0; i < this->pillars.size(); ++i ) {
this->pillars[i]->Update();
if( !this->pillars[i]->CanMove() && !this->pillars[i]->IsInQueue ) {
this->queue.push( i );
// std::cout << "\nPushed: " << i;
this->pillars[i]->IsInQueue = true;
}
}
}
void PillarManager::Draw( Shader& shader, Camera& camera ) {
for( int i = 0; i < Globals::PILLAR_COUNT; ++i )
this->pillars[i]->Draw( shader, camera );
}
void PillarManager::Draw( Shader& shader1, Shader& shader2, Camera& camera ) {
for( int i = 0; i < Globals::PILLAR_COUNT; ++i ) {
if( this->pillars[i]->IsSelected ) {
this->pillars[i]->Draw( shader2, camera );
} else {
this->pillars[i]->Draw( shader1, camera );
}
}
}
void PillarManager::Reset() {
time( &this->startTime );
for( int i = 0; i < Globals::PILLAR_COUNT; ++i ) {
// Push all the pillars to the queue
if( !this->pillars[i]->IsInQueue ) {
this->queue.push( i );
this->pillars[i]->IsInQueue = true;
}
this->pillars[i]->Reset();
}
}
std::vector<Rectangle*> PillarManager::GetAllRectangles() {
std::vector<Rectangle*> rects;
for( int i = 0; i < Globals::PILLAR_COUNT; ++i ) {
rects.push_back( pillars[i]->lowerRect );
rects.push_back( pillars[i]->upperRect );
}
return rects;
}
void PillarManager::IncreaseVelocity() {
for( int i = 0; i < Globals::PILLAR_COUNT; ++i ) {
pillars[i]->IncreaseVelocity();
}
}
float PillarManager::GetVelocity() {
return pillars[0]->GetCurrentVelocity();
}
Pillar& PillarManager::GetNearestPillarTo( const glm::vec3& position ) {
float xDist = INFINITY;
Pillar* pillar = this->pillars[0];
for( int i = 0; i < Globals::PILLAR_COUNT; ++i ) {
float x = this->pillars[i]->GetXPos() +
Globals::PILLAR_WIDTH / 2;
if( x > position.x ) {
float dist = x - position.x;
if( dist < xDist ) {
xDist = dist;
pillar = this->pillars[i];
}
}
}
return *pillar;
}
PillarManager::~PillarManager() {
for( int i = 0; i < Globals::PILLAR_COUNT; ++i )
delete this->pillars[i];
}