Jump to content
  • Advertisement
Sign in to follow this  
ahmedjbh

Sorry its a basic q on how to make many bricks

This topic is 5100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Thanks dan,

I knew about the contrucotrs but when i previous attmepted to use it, bad things happened :(


ok thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!