Hi, I edited this code based on what I've learned about sphere-sphere collision detection. The key to sphere-sphere collision detection is to check if sum of their radius is greater then distance between their middle points, and not just their position as it is done in the original code. For less operations to take place, we use square values. I added ball-wall collision, where wall is not a polygon, but simple plane(not visible). Note that each ball should be paired with each ball and each wall (at the moment it is not so). Adding more balls is now simpler because of new Ball structure. But, adding more and more balls and walls would require some kind of array and space structure to handle them all. Hope this helps someone: http://pastebin.com/H572Fgpf