-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBombEffect.cpp
More file actions
126 lines (120 loc) · 2.6 KB
/
BombEffect.cpp
File metadata and controls
126 lines (120 loc) · 2.6 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
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
#include "stdafx.h"
#include "BombEffect.h"
void Explosion_effect::init()
{
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 30; j++)
{
Particle_x[i][j] = 0;
Particle_y[i][j] = 0;
Particle_z[i][j] = 0;
velocity[i][j] = 1.6 + (float)(rand() % 30) / 10.0f;
Radius[i][j] = 0;
Particle_dead[i][j] = false;
}
}
Explode = false;
velocity[29][29] = 1.5;
}
GLvoid Explosion_effect::draw(Vector3D pos)
{
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat color[] = { 0.18f, 0.18f, 1.0f, 0.7f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
glMateriali(GL_FRONT, GL_SHININESS, 128);
glColor4f(0.18, 0.18, 1.0, 1.0);
if (Explode)
{
glPushMatrix();
{
glTranslatef(0, 0, 0);
glTranslatef(pos.x, -40, pos.z);
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 30; j++)
{
Particle_x[i][j] = ((Radius[i][j] * cos((j * 12)*RAD))*(cos((i * 12)*RAD)));
Particle_y[i][j] = ((Radius[i][j] * sin((i * 12)*RAD)));
Particle_z[i][j] = ((Radius[i][j] * sin((j * 12)*RAD))*(cos((i * 12)*RAD)));
}
}
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 30; j++)
{
if (!Particle_dead[i][j])
{
glPushMatrix();
glTranslatef(Particle_x[i][j], Particle_y[i][j], Particle_z[i][j]);
glutSolidCube(1);
glPopMatrix();
}
}
}
}
glPopMatrix();
}
}
GLvoid Explosion_effect::animation()
{
if (Explode)
{
for (int i = 0; i < 30; i++)
{
for (int j = 0; j < 30; j++)
{
if ((Particle_x[i][j] < -10 || Particle_x[i][j] > 10)
|| (Particle_z[i][j] < -10 || Particle_z[i][j] > 10)
|| (Particle_y[i][j] < -10 || Particle_y[i][j] > 10))
{
Particle_dead[i][j] = true;
}
else
Radius[i][j] += velocity[i][j];
}
}
}
if (Particle_dead[29][29])
{
Explode = false;
init();
}
}
GLvoid Bomb::draw(Vector3D pos)
{
glPushMatrix();
{
GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat color_bomb[] = { 0.2f, 0.2f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color_bomb);
glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
glMateriali(GL_FRONT, GL_SHININESS, 64);
glColor4f(0.2, 0.2, 1.0, 1.0);
glTranslatef(0, 0, 0);
glTranslatef(pos.x, y, pos.z);
glPushMatrix();
{
glutSolidSphere(10, 20, 20);
}
glPopMatrix();
glPushMatrix();
{
glTranslatef(0, 10, 0);
glRotatef(90, 1, 0, 0);
glutSolidTorus(2, 1.5, 25, 15);
}
glPopMatrix();
}
glPopMatrix();
}
void Bomb::init()
{
y = 400;
velocity = rand() % 25 + 5;
range =/* rand() % 3 +*/ 3;
isdraw = true;
isfalling = true;
count = 0;
}