Pong – Collision Detection

The collision detection algorithm is based on the lecture from the course “Advanced Game and Simulation Programming” at Narvik University College.

Pseudocode for the collision detection algorithm:

  • Calculate the physical properties (velocity, displacement, acceleration, etc.) for the ball and the paddles.
  • Looking for collision between the ball, the walls and the paddles. If any collision occur, create a collision object and register it in an array of collisions.
  • Make the array of collisions unique by removing duplicated collision objects.
  • Sort the array of collisions depending on the time of collision. The first collision should be handled first.
  • For every collision object in the array:
    • Pop the first element to handle.
    • Move the ball (or the paddle) to the point of impact.
    • Compute new physical properties.
    • Looking for collision between the ball, the walls and the paddles for the remaining time step. Register collision object into the array of collisions if any collision occurs.
    • Make the array of collision unique.
    • Sort the array.

=> Back to Pong