Okay so I have a comet the code is as follows:
import greenfoot.*;
import java.awt.Color;
import java.util.List;
/**
* Write a description of class Comet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Comet extends SmoothMover
{
// constants
private static final double GRAVITY = 1.9;
private static final Color defaultColor = new Color(255, 216, 0);
// fields
private double mass;
private Color color;
/**
* Construct a comet with default size, mass, movement and color.
*/
public Comet()
{
this (20, 300, new Vector(0, 1.0), defaultColor);
}
/**
* Construct a comet with a specified size, mass, movement and color.
*/
public Comet(int size, double mass, Vector movement, Color color)
{
this.mass = mass;
addForce(movement);
GreenfootImage image = new GreenfootImage (size, size);
image.setColor (color);
image.fillOval (0, 0, size-1, size-1);
setImage (image);
this.color = color;
}
/**
* Act. That is: apply the gravitation forces from
* all other bodies around, and then move.
*/
public void act()
{
applyForces();
move();// To be done - not yet implemented
getWorld().getBackground().setColorAt(getX(), getY(), color);
checkCollision();
}
/**
* Apple the forces of gravity from all other celestial bodies in
* this universe.
*/
private void applyForces()
{
List<Comet> comets = getWorld().getObjects(Comet.class);
for (Comet comet : comets)
{
if (comet != this)
{
applyGravity (comet);
}
}
}
/**
* Apply the gravity force of a given comet to this one.
*/
private void applyGravity(Comet other)
{
double dx = other.getExactX() - this.getExactX();
double dy = other.getExactY() - this.getExactY();
Vector force = new Vector (dx, dy);
double distance = Math.sqrt (dx * dx + dy * dy);
double strength = GRAVITY * this.mass * other.mass /
(distance * distance);
double acceleration = strength / this.mass;
force.setLength (acceleration);
addForce (force);
}
/**
* Return the mass of this comet.
*/
public double getMass()
{
return mass;
}
/**
* Check whether we are colliding with another planet
*/
private void checkCollision()
{
Comet a = (Comet) getOneIntersectingObject(Comet.class);
if(a != null) {
getWorld().addObject(new Explosion(), getX(), getY());
getWorld().removeObject(this);
}
}
}
When it is in the Space it doesn't collide or react with other objects like my sun and planets. Help please!

