Sign in to follow this  
phil67rpg

pong

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
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

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