pong
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
If you are using C or C++:
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.
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();
}
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
Popular Topics
Advertisement