-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopponentqueue.cpp
More file actions
59 lines (52 loc) · 1.36 KB
/
opponentqueue.cpp
File metadata and controls
59 lines (52 loc) · 1.36 KB
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
#include "opponentqueue.h"
OpponentQueue::OpponentQueue()
{
oppWidth = 50;
oppHeight = 75;
opponentQueue = new QQueue<Opponent *>();
timer = DEFAULT_TIMER;
}
void OpponentQueue::render()
{
QList<Opponent *>::Iterator i;
glEnable(GL_TEXTURE_2D);
for(i = opponentQueue->begin(); i != opponentQueue->end(); ++i)
{
Opponent *opp;
opp = *i;
opp->render();
opp->setCenterY(opp->getCenterY() - speed);
if(opp->getCenterY() < 0)
{
opponentQueue->erase(i);
}
}
glDisable(GL_TEXTURE_2D);
timer -= speed;
if(timer <= 0)
{
Opponent *opp = new Opponent(QPoint(rand() % (rightBoundary - leftBoundary) + leftBoundary, startY + 25), oppWidth, oppHeight, texture);
opp->setSpeed(speed);
opponentQueue->append(opp);
timer = DEFAULT_TIMER;
}
}
void OpponentQueue::loadTexture()
{
texture = SOIL_load_OGL_texture("images/opponent.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);
if(texture == 0)
{
std::cout << "Unable to load texture" << std::endl;
}
}
void OpponentQueue::setSpeed(int speed)
{
this->speed = speed;
QList<Opponent *>::Iterator i;
for(i = opponentQueue->begin(); i != opponentQueue->end(); ++i)
{
Opponent *opp;
opp = *i;
opp->setSpeed(this->speed);
}
}