sprite
Class SimpleGun

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

public class SimpleGun
extends Sprite

A sprite that represents a gun. The gun can shoot Bullet sprites. The gun is shown as a blue ball with a gun barrel sticking out of it. The barrel points in the direction that bullets will be shot.


Field Summary
 
Fields inherited from class sprite.Sprite
EXIT_POLICY_BOUNCE, EXIT_POLICY_DIE, EXIT_POLICY_STOP, EXIT_POLICY_WRAP
 
Constructor Summary
SimpleGun()
          Creates a gun whose barrel initially points up.
 
Method Summary
 void draw(java.awt.Graphics g)
          This method is called by the SpritePanel to tell the sprite to draw itself.
 void fire()
          Fire a bullet by adding a Bullet sprite to the panel that contains this GunSprite.
 double getAngle()
           
 double getBulletSpeed()
           
 void setAngle(double degrees)
          Sets the direction that the gun is pointing.
 void setBulletSpeed(double speed)
          Sets the speed for bullets fired by this gun.
 
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

SimpleGun

public SimpleGun()
Creates a gun whose barrel initially points up. It shoots bullets that have a speed of 10.

Method Detail

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

fire

public void fire()
Fire a bullet by adding a Bullet sprite to the panel that contains this GunSprite. The bullet's speed is given by the gun's bulletSpeed property. The direction of the bullet is given by the direction the gun is pointing. (If the gun is not in a panel, this method does nothing.)


getAngle

public double getAngle()

getBulletSpeed

public double getBulletSpeed()

setAngle

public void setAngle(double degrees)
Sets the direction that the gun is pointing. The angle is given in degrees, with zero degrees pointing up. Positive angles are measured clockwise from that position; negative angles, counterclockwise.


setBulletSpeed

public void setBulletSpeed(double speed)
Sets the speed for bullets fired by this gun.