-
Notifications
You must be signed in to change notification settings - Fork 0
/
Asteroid.cpp
58 lines (48 loc) · 1.48 KB
/
Asteroid.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
/*
* Asteroid.cpp
* Allenroids
*
* Created by Allen Smith on Sat Jun 19 2004.
*
*/
#include "Asteroid.h"
#include <stdlib.h>
const int Asteroid::asteroidSizes[3] = {10, 20, 30};
/****************************************************
* constructor
* creates an asteroid of the specified size at the specified location, with no velocity
***************************************************/
Asteroid::Asteroid(int sizeCode, float positionX, float positionY){
size = sizeCode; //an index used to look up the actual radius in asteroidSizes
radius = asteroidSizes[sizeCode]; //lookup the value
mass = (size+1)*24;
impacted.hitCode = false;
color[0] = 106; //derivative of "eggplant" in the crayon box
color[1] = 0;
color[2] = 211;
//make it so they're not all the same color
color[0] += (rand() % 24) * (GLubyte)pow(-1, rand());
color[1] += rand() % 24;
color[2] += (rand() % 24) * (GLubyte)pow(-1, rand());
position.x = positionX;
position.y = positionY;
direction.x = 0;
direction.y = 0;
rotationAngle = rand()%360;
}
/****************************************************
* draw
* generically paints the asteroid at the origin
***************************************************/
void Asteroid::draw() const{
float angle;
static int numberVertices = 7;
glRotatef(rotationAngle, 0,0,1);
glColor3ubv(color);
glBegin(GL_TRIANGLE_FAN);
for(angle = 0; angle < 2*PI; angle += 2*PI/numberVertices){
glVertex2f( radius*cos(angle),
radius*sin(angle) );
}
glEnd();
}