-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPellet.cpp
More file actions
148 lines (131 loc) · 3.83 KB
/
Pellet.cpp
File metadata and controls
148 lines (131 loc) · 3.83 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "Pellet.h"
Pellet::Pellet( GLfloat xPos,GLfloat yPos,GLfloat zPos, GLint colorFlag, GLint type): Sprite()
{
this->x=xPos;
this->y=yPos;
this->z=zPos;
this->hasBeenEaten=0;
this->colorFlag = colorFlag;
this->type = type;
this->textureSwitch = 1;
if(this->type==1)
this->size = 0.5;
else
this->size = 0.3;
this->loadTexture();
}
Pellet::~Pellet()
{
//dtor
}
GLint Pellet::getHasBeenEaten()
{
return this->hasBeenEaten;
}
GLint Pellet::eat()
{
this->hasBeenEaten=1;
return this->type;
}
void Pellet::draw()
{
if(this->hasBeenEaten==1)
return;
glPushMatrix();
GLfloat yellow[] = { 1.0f, 1.0, 0.0, 1.0 };
GLfloat red[] = { 0.8f, 0.0, 0.0, 1.0 };
GLfloat orange[] = { 1.0f, 0.65f, 0.0, 1.0 };
GLfloat purple[] = { 0.58f, 0.0f, 0.83f, 1.0 };
GLfloat blue[] = { 0.0, 0.2f, 1.0, 1.0 };
GLfloat cyan[] = { 0.0, 1.0f, 1.0, 1.0 };
GLfloat pink[] = { 1.0f, 0.08f, 0.58f, 1.0 };
GLfloat ambient[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat shininess[] = { 100.0 };
switch (this->colorFlag)
{
case 1:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, purple);
break;
case 2:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
break;
case 3:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cyan);
break;
case 4:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, orange);
break;
case 5:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, pink);
break;
default:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
break;
}
// setup texture mapping
//if(this->type==1)
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambient);
if(this->textureSwitch==0)
glDisable( GL_TEXTURE_2D );
else
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, this->texture);
glColor3f(1.0f,1.0f,1.0f);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
move();
glRotatef(180.0f, 1.0f, 0.0f,0.0f);//Flip sphere so we do not see texture seem.
GLUquadricObj* l_poQuadric = gluNewQuadric();
gluQuadricDrawStyle(l_poQuadric, GLU_FILL);
gluQuadricNormals(l_poQuadric, GLU_SMOOTH);
gluQuadricTexture(l_poQuadric, GL_TRUE);
gluSphere(l_poQuadric,this->size,24,24);
gluDeleteQuadric(l_poQuadric);
glPopMatrix();
glEnable( GL_TEXTURE_2D );
}
void Pellet::setTextureSwitch(GLint state)
{
this->textureSwitch = state;
}
int Pellet::getType()
{
return this->type;
}
int Pellet::loadTexture()
{
// Load Bitmaps And Convert To Texture
if(this->type==1)
{
texture = SOIL_load_OGL_texture
( //"/home/angela/Documents/Comp371Project/data/pellet2.bmp",
"data/pellet2.bmp",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y
);
}
else
{
texture = SOIL_load_OGL_texture
(
//"/home/angela/Documents/Comp371Project/data/pellet1.bmp",
"data/pellet1.bmp",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y
);
}
if(texture == 0)
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result());
return false;
}
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
return true; // Return Success
}