import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;

class Bomb extends GameObject
{
    final int bombWidth = 19;
    final int bombHeight = 26;
    
    int x, y, endx, endy, speed;
    Image bombImage;
    MissileCommando parent;
    
    Bomb (int startx, int starty, int endx, int endy, int speed, Image bombImage, MissileCommando parent)
    {
	this.x = startx;
	this.y = starty;
	this.endx = endx;
	this.endy = endy;
	this.speed = speed;
	this.bombImage = bombImage;
	this.parent = parent;
    }

    void erase (Graphics g)
    {
	g.setColor (skyColor);
	g.fillRect (x - bombWidth/2, y - bombWidth/2, bombWidth, bombHeight);
    }

    void paint (Graphics g)
    {
	erase (g);

	if (!alive)
	{
	    return;
	}
	else if (explode)
	{
	    alive = false;
	    explode = false;
	    return;
	}

	y += speed;

	if (y > endy)
	{
	    alive = false;
	}

	if (alive)
	{
	    g.drawImage (bombImage, x - bombWidth/2, y - bombWidth/2, bombWidth, bombHeight, parent);
	}
    }

    boolean collision (int x2, int y2, int range)
    {
	if (!alive || explode)
	{
	    return false;
	}
	
	int distance = (int) Math.sqrt (((x2 - x) * (x2 - x))
					+ ((y2 - y) * (y2 - y)));
	range += bombWidth/2;
	return distance <= range;
    }

    boolean collision (int x2, int y2, int w, int h)
    {
	if (!alive || explode)
	{
	    return false;
	}
	
	return x >= x2 && x <= (x2 + w) && y >= y2 && y <= (y2 + h);
    }
}