well I stubbed out the above code, I am still confused on how to declare the g_bBlock statement.
#include <iostream>
#include <glut.h>
using namespace std;
const int ENUM_TOTAL_BLOCKS = 15;
bool g_bBlock[15];
int main()
{
for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {
if ( g_bBlock.Visible() ) {
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(g_bBlock.x, 4.0f, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(g_bBlock.x+2.0f, 4.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(g_bBlock.x+2.0f, 3.5f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(g_bBlock.x, 3.5f, 0.0f);
glEnd();
}
}
return 0;
}
little help
Firstly, if you define ENUM_TOTAL_BLOCKS and use it to run over the array, use it to declare the array too. Don’t use ENUM_TOTAL_BLOCKS in some places and 15 in other places. Use ENUM_TOTAL_BLOCKS everywhere.
You also have to initialize the blocks to make them all active and to set their starting positions.
Obviously, telling you how to do this means holding your hand and is not helping you grow on your own.
L. Spiro
class CBlock {
public :
bool m_bActive;
float m_fX;
};
CBlock g_bBlock[ENUM_TOTAL_BLOCKS];
for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {
if ( g_bBlock[I].m_bActive ) {
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(g_bBlock[I].m_fX, 4.0f, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(g_bBlock[I].m_fX+2.0f, 4.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(g_bBlock[I].m_fX+2.0f, 3.5f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(g_bBlock[I].m_fX, 3.5f, 0.0f);
glEnd();
}
}
You also have to initialize the blocks to make them all active and to set their starting positions.
Obviously, telling you how to do this means holding your hand and is not helping you grow on your own.
L. Spiro
I want to thank spiro for all her help. Well I picked apart the following code she gave me. I have made some adjustments to it. What I am confused about is how the g_bBlock array works. All I get 3 5 5 3 for the output.
here is the stubbed out code.
here is the stubbed out code.
#include <iostream>
#include <glut.h>
using namespace std;
const int ENUM_TOTAL_BLOCKS = 15;
class CBlock {
public :
bool m_bActive;
float m_fX;
};
CBlock g_bBlock[ENUM_TOTAL_BLOCKS];
int main()
{
for ( int I = 0; I < ENUM_TOTAL_BLOCKS; ++I ) {
if ( g_bBlock.m_bActive ) {
glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 0.0f);
glVertex3f(g_bBlock.m_fX+3.0f, 4.0f, 0.0f);
glTexCoord2f(-1.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+5.0f, 4.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(g_bBlock.m_fX+5.0f, 3.5f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(g_bBlock.m_fX+3.0f, 3.5f, 0.0f);
glEnd();
}
}
cout << g_bBlock[0].m_bActive << endl;
cout << endl;
cout << g_bBlock[0].m_fX+3.0f << endl;
cout << g_bBlock[0].m_fX+5.0f << endl;
cout << g_bBlock[0].m_fX+5.0f << endl;
cout << g_bBlock[0].m_fX+3.0f << endl;
cout << g_bBlock[1].m_bActive << endl;
cout << endl;
cout << g_bBlock[1].m_fX+3.0f << endl;
cout << g_bBlock[1].m_fX+5.0f << endl;
cout << g_bBlock[1].m_fX+5.0f << endl;
cout << g_bBlock[1].m_fX+3.0f << endl;
return 0;
}
You never initialized the data held within g_bBlock. This is a one-time pass over the array to set the default values you want the blocks to have.
L. Spiro
L. Spiro
That is one way it could be done, except that you have only defined one block (assuming you also fix the syntax).
L. Spiro
L. Spiro
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement