-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKerblooie.cpp
68 lines (57 loc) · 2.06 KB
/
Kerblooie.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
/*
* Kerblooie.cpp
* Allenroids
*
* Class for explosion particles
*
* Created by Allen Smith on Thu Jun 17 2004.
*
*/
#include "Kerblooie.h"
const int Kerblooie::kerblooieSizes[6] = {6, 24, 36, 48, 60, 72};
/****************************************************
* constructor
***************************************************/
Kerblooie::Kerblooie(){}
/****************************************************
* constructor
***************************************************/
Kerblooie::Kerblooie(Coordinate positionIn, Vector directionIn, int lifespanIn, float particleDiameter, GLubyte *colorHint){
int counter;
position = positionIn;
direction = directionIn;
mass = 0; //hardly worth setting
lifespan = lifespanIn;
timeToLive = lifespan; //it was just born, and has as long to life as it is supposed to
radius = particleDiameter/2; //I don't know why I use diameters here
for(counter = 0; counter < 3; counter++)
color[counter] = colorHint[counter] + rand()%(256-colorHint[counter])*(int)pow(-1,rand()); //takes hinted color and gives it some variation
color[3] = 255; //starts out at maximum brightness
}
/****************************************************
* drawInGame
* overrides the edge-wrapping features in the superclass
* they aren't needed for such simple explosion particles
***************************************************/
void Kerblooie::drawInGame() const{
glPushMatrix();
glTranslatef(position.x, position.y, 0);
draw();//just call the main draw function
glPopMatrix();
}
/****************************************************
* draw
* paints the kerblooie particle
***************************************************/
void Kerblooie::draw() const{
float angle; //used to draw round particle
float randomParticleSize; //each kerblooie particle's size is set to "twinkle" slightly
glColor4ubv( color );
randomParticleSize = radius + (rand()%2 * 0.25)/2;
glBegin(GL_TRIANGLE_FAN);
for(angle = 0; angle < 2*PI; angle += 2*PI/5){
glVertex2f( randomParticleSize*cos(angle),
randomParticleSize*sin(angle) );
}
glEnd();
}