September 01 2012 · python · pygame

Bouncing Balls with Pygame

Bouncing Balls with Pygame

I have recently played around with Pygame module. It was a fun experience. I decided to use Pygame to write a simple classic bouncing balls simulation.

You can have a look at the code here

The Ball object has methods to detect collisions with walls and other balls; callable method update() to update its position and method draw to redraw. BallWorld is the Game object containing game logics. It contains the list of balls, loop through all balls to update their positions each refresh.

A few things to note:

Have fun !.

Ah, well, it is not actually a game per se, but it is fun to watch all the balls bouncing. You can try to adjust the number of balls, speeds, etc...