DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004

    pong ball movemet?

    Hey does anyone know how to make the ball bounce like it does in pong? Like if it is going towards the bottom of the screen it bounces up at the angle its supposed to?
    They say if you play a Microsoft Windows CD backwards it will play satanic messages. But thats nothing, if you play it forwards it installs Windows.

  2. #2
    Join Date
    Feb 2004
    Well I would store the velocity of the ball as an X and Y value (with X and Y having the usual definition for a cartesian coordinate system, X being horizontal and Y being vertical). This would be the velocity that the ball was travelling in say pixels per unit time.

    When the ball hits the edge you want it to rebound from the surface at the same angle that it hit it, at the same speed that it hit it. The velocity would have the same magnitude, but would be of opposite sign in the appropriate direction.

    For example if the ball hits the bottom or top edge at velocity (X,Y), it will change it's velocity to (X,-Y). If it hits the left or right edge at velocity (X,Y) it will leave at velocity (-X,Y). Obviously this is a very simplistic model. It doesn't allow for spin or for friction. The ball will just keep bouncing around forever at the same speed. That may be ok for playing pong though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.