import java.awt.*;

public class Ball {
    private int x, y;
    private int vX, vY;
    private final int radius;
    private final Color color;
    private final Image image;

    public Ball(int x, int y, int vX, int vY, int radius, Color color, Image image)
    {
        this.x = x;
		this.y = y;
        this.vX = vX;
        this.vY = vY;
        this.radius = radius;
        this.color = color;
        this.image = image;
    }

    public void move(int width, int height)
    {
        // moves the ball's center
		x += vX;
		y += vY;

        // rebound
        if (x - radius <= 0 || x + radius >= width) {
            vX = -vX;
        }
        if (y - radius <= 0 || y + radius >= height) {
            vY = -vY;
        }
    }

    public void draw(Graphics2D g)
    {
        if (image == null) {
            g.setColor(color);
            g.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
        }
        else {
            g.drawImage(image, x - radius, y - radius, 2 * radius, 2 * radius, null);
        }
    }
}
