pong

Started by
1 comment, last by phil67rpg 18 years, 1 month ago
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
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.
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();
}

This topic is closed to new replies.

Advertisement