import body, randomBody, visual, time

class SolarSystem(object):
    def __init__(self, planets):
        self.sun = body.Body(color=visual.color.yellow)
        self.planets = [randomBody.RandomBody()
                               for i in range(planets)]
        self.planets.append(self.sun)
    def move(self):
        for planet in self.planets:
            for otherPlanet in self.planets:
                if planet != otherPlanet:
                    planet.applyForce(planet.gravity(otherPlanet))
                    if planet.is_colliding(otherPlanet):
                        self.collide(planet, otherPlanet)
			
    def collide(self, p1, p2):
        colliders = [p1, p2]
        colliders.sort(reverse=True)
        colliders[1].explode()
        colliders[0].absorb(colliders[1])
        self.planets.remove(colliders[1])
