
/**
 * Bullet.java
 *
 * the bullet updates itself, etc..
 * 
 * Created: Sat Apr  8 15:43:08 2000
 *
 * @author root
 * @version
 */


import java.awt.*;
import java.lang.Math;

public class Bullet {
  protected Rectangle location; // location of the bullet object
  protected double dx, dy;  // direction vectors of bullet
  protected int x, y;       // current position of bullet
  protected Color color;
  protected String owner;  // who owns the bullet
  
  public Bullet (int x, int y, double dx, double dy, String owner) {
    location = new Rectangle (x, y, 1, 1);     // bullet is tiny 
    this.dx = dx;
    this.dy = dy;
    this.color = Color.red;
    this.owner = owner;
  }

  public Bullet (int x, int y) {
    location = new Rectangle (x, y, 1, 1);
    dx = 0.0;
    dy = 0.0;
  }

  public void setColor (Color newColor) { color = newColor; }

  public void setMotion (double ndx, double ndy) { dx = ndx; dy = ndy; }

  // bulletOwner is in the following format: bulletXXXX
  public String bulletOwner() { return owner; }
  
  public int x() { return location.x; }

  public int y() { return location.y; }

  public double xMotion() { return dx; }

  public double yMotion() { return dy; }

  public void moveTo (int x, int y) { location.setLocation (x, y); }

  public void move() {
    location.translate ((int) (dx + Math.random()*2 - 1.0) ,
                        (int) (dy + Math.random()*2 - 1.0)); }
  
  private double radian (double angle) { return angle * 2.0* Math.PI / 360.0; } 

  // flicker free paint...
  public void draw (Graphics g) {
    g.setColor (color);
    g.drawOval (location.x,
                location.y,
                2, 2);
  }
  
  private void delay (int millis) {
    try { Thread.sleep (millis); } catch (Exception ignored) {}
  }
} // Bullet




