sprite
Class Bullet

java.lang.Object
  extended by sprite.Sprite
      extended by sprite.Bullet

public class Bullet
extends Sprite

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, 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.


Field Summary
 
Fields inherited from class sprite.Sprite
EXIT_POLICY_BOUNCE, EXIT_POLICY_DIE, EXIT_POLICY_STOP, EXIT_POLICY_WRAP
 
Constructor Summary
Bullet(double x, double y, double dx, double dy)
          Creates a bullet at a specified location and with a specified velocity.
 
Method Summary
 void detonate()
          Kill the bullet and, if it is exploding, add an Explosion to the SpritePanel.
 void draw(java.awt.Graphics g)
          This method is called by the SpritePanel to tell the sprite to draw itself.
 boolean getExploding()
           
 void setColor(java.awt.Color c)
          Change the color of this Bullet.
 void setExploding(boolean b)
          Sets the "exploding" property of this Bullet to true or false.
 
Methods inherited from class sprite.Sprite
contains, die, getDx, getDy, getExitPolicy, getHome, getSpriteHeight, getSpriteWidth, getX, getY, isDead, isImmuneToBullets, onDeath, prepareForNextFrame, randomVelocity, setDx, setDy, setExitPolicy, setImmuneToBullets, setLocation, setSpriteHeight, setSpriteWidth, setUseOvalForContains, setVelocity, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bullet

public Bullet(double x,
              double y,
              double dx,
              double dy)
Creates a bullet at a specified location and with a specified velocity.

Parameters:
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
Method Detail

detonate

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.)


draw

public void draw(java.awt.Graphics g)
Description copied from class: Sprite
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.

Overrides:
draw in class Sprite

getExploding

public boolean getExploding()

setColor

public void setColor(java.awt.Color c)
Change the color of this Bullet. If the color is null, then black is used.


setExploding

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.