actually I have done pong before in glut, I want to finish this game, can I please get some help on this problem.
sprite collision
You said you've tried isolating rendering of the "drawcollision_one" function, and it displayed the collision graphic. This function is being called directly by the "coll_plane_one" function. Is perhaps your game loop calling "coll_plane_one", and then later clearing the buffer before it draws the bullet and plane?
It's helpful to organize your game loop to update the entire game state first, then perform all of your rendering in one go.
When you call "checkCollide", you could instead set a variable (let's say, "bool drawCollisionFlag"). And then in your draw / render pass, check the value of that flag and call "drawcollision_one" if true.
Senior software developer with a passion for games, still hoping to break into the industry after all these years...
13 minutes ago, rileyman said:It's helpful to organize your game loop to update the entire game state first, then perform all of your rendering in one go.
can you explain this more specifically.
Eep, I'll do my best. ?
Updating your game state is where you're changing all the variable values... Changing the position of the bullet and plane you already know. Setting a flag indicating whether a collision occurred can be another part of your game state.
Rendering is where you draw everything. What I suspect is that the following is happening:
- If a collision occurred, draw the collision sprite.
- Clear the buffer.
- Draw the bullet and plane.
- Swap the buffer to the screen (ie. the "glutPostRedisplay" call).
To make sure everything you're drawing actually gets shown on the screen, you need to clear the buffer first, then draw everything, then call "glutPostRedisplay" at the end (and only once).
Articles like this one covering game loops are good reading for any game dev.
Senior software developer with a passion for games, still hoping to break into the industry after all these years...
3 hours ago, rileyman said:When you call "checkCollide", you could instead set a variable (let's say, "bool drawCollisionFlag"). And then in your draw / render pass, check the value of that flag and call "drawcollision_one" if true.
well I tried this but still does not work
void coll_plane_one()
{
//draw bullet
float x = -2.5f + move_plane;
float y = -75.0f + up;
float oWidth = 5.0f;
float oHeight = 5.0f;
//draw plane
float xTwo = -10.0f + move_plane;
float yTwo = 100.0f + down;
float oTwoWidth = 20.0f;
float oTwoHeight = 20.0f;
if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
{
collision_flag = true;
cout << "Collision" << endl;
}
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[2]);
for (float i = -130.0f; i <= 130.0f; i += 40.0f)
{
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(i, 100.0f + down);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(i+20.0f, 100.0f + down);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(i+20.0f, 80.0f + down);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(i, 80.0f + down);
glEnd();
}
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-10.0f+move_plane, -80.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(10.0f+move_plane, -80.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(10.0f+move_plane, -100.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-10.0f+move_plane, -100.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-2.5f+move_plane, -75.0f+up);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(2.5f+move_plane, -75.0f+up);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(2.5f+move_plane, -80.0f+up);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-2.5f+move_plane, -80.0f+up);
glEnd();
if (collision_flag == true)
{
drawcollision_one();
}
coll_plane_one();
glPopMatrix();
glutSwapBuffers();
glDisable(GL_TEXTURE_2D);
}
9 hours ago, phil67rpg said:actually I have done pong before in glut, I want to finish this game
That tutorial is not about pong for you. It is about: collision detection, better code organisation, game loop in GLUT and so on.
1 hour ago, phil67rpg said:that site is not secure
Just allow your browser to load this site. Click the "Advanced" button in Chrome.
I wrote to author about this problem. Michael answered me:
QuoteHey,
sorry about that. I renewed the SSL certificate yesterday but it didn't seem to work yet. We'll work on it
Based on the code you're showing above, you're checking whether "collision_flag" is true before you call the "coll_plane_one" function, which is where you set that flag.
I also would have expected the "coll_plane_one" call to occur in the update phase of the game loop, but that isn't the actual cause of the issue. It's still hard to tell if there might be other issues causing the collision sprite to not appear, as we're only seeing snippets of the entire program at different points in time. It's probably going to come down to stepping through your code and watching variable values change in the debugger.
Senior software developer with a passion for games, still hoping to break into the industry after all these years...