java.lang.Objectsprite.Sprite
sprite.Bullet
public class Bullet
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 |
---|
public Bullet(double x, double y, double dx, double dy)
x
- the x-component of the initial locationy
- the y-component of the initial locationdx
- the x-component of the velocitydy
- the y-component of the velocityMethod Detail |
---|
public void detonate()
public void draw(java.awt.Graphics g)
Sprite
draw
in class Sprite
public boolean getExploding()
public void setColor(java.awt.Color c)
public void setExploding(boolean b)