Game Programming: Planetary Physics Fun
Full netbeans project: https://www.dropbox.com/s/vy7kvlqfmggtdqy/OrbitBall%20%28Netbeans%20project%29.zip?dl=0
Planet masses are determined by their area (pi * radius²), which determines how strong their gravity is. Every planet affects every other planet, no matter how far apart they are. This causes planets to be attracted to the total center of mass of all other planets. If there are 100 planets, each planet needs to look at 99 other planets, every single update of the primary loop.
I still might add semi elastic collisions (so glancing collisions will not cause merging). Maybe powerful collisions will cause planets to break apart or eject smaller pieces while conserving total mass.
Currently when 2 planets collide and merge, the resulting planet's size is just determined by adding the areas of the original planets, and a radius is calculated from that. The new planet's position, velocity, and color values are found by looking at the proportion of the masses of the original planets.
Music: Ronald Jenkees - Simpletank
■ Website: http://jnumerical.com