Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

pong

This topic is 4453 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

I am still trying to animate a pong ball, I have managed to get it to move in one direction but I want it to go in a random direction from the center of the screen, I am using openGL to develop this game, I also need some instructioon on collision detection

Share this post


Link to post
Share on other sites
Advertisement
If you are using C or C++:


double vel_x,vel_y;
const double VEL_MAX = /* something here */;

void start_ball_velocity()
{
vel_x = (rand()/100)%VEL_MAX;
vel_y = (rand()/100)%VEL_MAX;
}





Lazy Foo has some nice 2D collision detection tutorials. Check Lesson 13 and Lesson 14. He uses SDL on those, but you don't need SDL to learn that.

Share this post


Link to post
Share on other sites
here is a code snippet to animate pong ball


void PongBall(void)
{

glColor3f(0.0f,0.0f,0.0f);

glBegin(GL_POLYGON);
glVertex2i(m+380,n+280);
glVertex2i(m+400,n+280);
glVertex2i(m+400,n+300);
glVertex2i(m+380,n+300);
glVertex2i(m+380,n+280);
glEnd();

m++;
n++;

glColor3f(1.0f,1.0f,1.0f);

glBegin(GL_POLYGON);
glVertex2i(m+380,n+280);
glVertex2i(m+400,n+280);
glVertex2i(m+400,n+300);
glVertex2i(m+380,n+300);
glVertex2i(m+380,n+280);
glEnd();

glutSwapBuffers();
}

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!