A Bullet is a special type of Sprite. A SpritePanel keeps track of bullets separately
from other sprites . The default behavior is that when a sprite contains the location
of a bullet, both the sprite and the bullet die, and if the bullet's "exploding" property
is true then an Explosion sprite is placed at the location of the bullet. It is possible
to make sprites immune to bullets. By default, a bullet will also die when it moves outside
the SpritePanel. (One way to add a bullet to a panel is by firing a Gun sprite.) Bullets
are shown by default as small black ovals. You shouldn't make them too big: only the center
of the bullet is used when testing if it has hit a sprite.
public Bullet(double x,
Creates a bullet at a specified location and with a specified velocity.
x - the x-component of the initial location
y - the y-component of the initial location
dx - the x-component of the velocity
dy - the y-component of the velocity
public void detonate()
Kill the bullet and, if it is exploding, add an Explosion to the SpritePanel.
This is ordinarily only called by a SpritePanel when the bullet hits another
sprite. (You could, however, call it for other reasons.)
This method is called by the SpritePanel to tell the sprite to draw itself.
It is not meant to be called directly. Subclasses should override this method
to draw an appropriate picture. The method in this class just draws a tiny
black dot at the location of the sprite.
Change the color of this Bullet. If the color is null, then black is used.
public void setExploding(boolean b)
Sets the "exploding" property of this Bullet to true or false. When this property is true,
then when the bullet hits and destroys a sprite, an Explosion is added to the panel at the
point where the bullet died.