-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcExplosion.cpp
129 lines (101 loc) · 2.09 KB
/
cExplosion.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
118
119
120
121
122
123
124
125
126
127
128
129
#include "cExplosion.h"
cExplosion::cExplosion(void)
{
}
cExplosion::cExplosion(bool act, int currAnim, float x, float y, int type, int delay)
{
this->active = act;
this->currAnim = currAnim;
this->x = x;
this->y = y;
this->type = type;
this->setType(type);
this->delayAnim = delay;
}
void cExplosion::setActive(bool a)
{
this->active = a;
}
bool cExplosion::getActive()
{
return this->active;
}
void cExplosion::setCurrAnim(int anim)
{
this->currAnim = anim;
}
int cExplosion::getCurrAnim()
{
return this->currAnim;
}
void cExplosion::setType(int type)
{
this->type = type;
if(this->type == 1) {
p.xo = 128;
p.xf = 160;
p.yo = 1;
p.yf = 33;
}
//else if(){}
}
int cExplosion::getType()
{
return this->type;
}
void cExplosion::setPosXY(int x,int y)
{
this->x = x;
this->y = y;
}
void cExplosion::getPosXY(int *x, int *y)
{
*x = this->x;
*y = this->y;
}
float calculeOffset(int w, int anim)
{
if(anim == 0) return 0.0f;
else return (anim) * 33;
}
void cExplosion::Draw(int id)
{
float x, y, w, h, offset;
x = this->x;
y = this->y;
w = (this->p.xf) - (this->p.xo);
h = (this->p.yf) - (this->p.yo);
if (this->delayAnim == EXPLOSION1_TRANSITION_SPEED) {
this->delayAnim = 0;
this->currAnim++;
}
else this->delayAnim++;
offset = calculeOffset(w, this->currAnim);
h*=2;
w*=2;
float xo, yo, xf, yf;
if (this->type == 1) {
offset /= IMG_WIDTH_EXPLOSION1;
xo = this->p.xo / IMG_WIDTH_EXPLOSION1;
xf = this->p.xf / IMG_WIDTH_EXPLOSION1;
yo = this->p.yo / IMG_HEIGHT_EXPLOSION1;
yf = this->p.yf / IMG_HEIGHT_EXPLOSION1;
glEnable(GL_TEXTURE_2D);
glColor4f(1.0, 1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, id);
glBegin(GL_QUADS);
glTexCoord2f(xo + offset, yo); glVertex2d(x, y);
glTexCoord2f(xf + offset, yo); glVertex2d((x + w), y);
glTexCoord2f(xf + offset, yf); glVertex2d((x + w), (y + h));
glTexCoord2f(xo + offset, yf); glVertex2d(x, (y + h));
glEnd();
glDisable(GL_TEXTURE_2D);
}
// type 1; 4 animations
if(this->type == 1 && this->currAnim == 6) {
this->active = false;
}
}
cExplosion::~cExplosion(void)
{
}