Sign in to follow this  
ahmedjbh

Sorry its a basic q on how to make many bricks

Recommended Posts

hi there, If Mr Nehe is around, i love your work. I am trying to make a break out game, its my first project in gl, i am self taught c++. My problem is that i want to make many blocks, now i tried to make a class called block, and re use it and just alter the translate posistion, but no luck. Can someone tell me how to set up a class in gl that will enable me to reuse it to make blocks? This was my patheticly wrong effort, i know its wrong because i have these funcs in the class, but i dont know how to do it. Ok thanks in advance guys. class block { public: float bxpos = 1.0f; float bypos = 0.0f; float bzpos = -10.0f; float bred = 0.0f; float bgreen = 0.0f; float bblue = 0.0f; glLoadIdentity(); glTranslatef(bxpos,bypos,bzpos); glColor3f(bred, bgreen, bblue); glBegin(GL_QUADS); glVertex3f( -0.3f, 0.0f, 0.0f); glVertex3f( 0.3f, 0.0f, 0.0f); glVertex3f( 0.3f,-0.2f, 0.0f); glVertex3f( -0.3f,-0.2f, 0.0f); glEnd(); };

Share this post


Link to post
Share on other sites
You werent far off at all in fact.
Heres what you would need.

class block
{
public:
block() // this is called the constructor function
{ //it gets called when you create a brick in your game, like
// block block1;
bxpos = 1.0f;
bypos = 0.0f;
bzpos = -10.0f;
bred = 0.0f;
bgreen = 0.0f;
bblue = 0.0f;
}

void RenderBlock() //since your game will be in a while loop, this will go in that loop as well
//block1.RenderBlock();
{
glLoadIdentity();
glTranslatef(bxpos,bypos,bzpos);
glColor3f(bred, bgreen, bblue);
glBegin(GL_QUADS);
glVertex3f( -0.3f, 0.0f, 0.0f);

glVertex3f( 0.3f, 0.0f, 0.0f);

glVertex3f( 0.3f,-0.2f, 0.0f);

glVertex3f( -0.3f,-0.2f, 0.0f);

glEnd();
}
float bxpos;
float bypos;
float bzpos;
float bred;
float bgreen;
float bblue;
};

it might still error because the constructor is INSIDE the class definition, if it does, move it out. hope that helps though
-Dan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this