Line Collision

Hello JGO,

I have a question. In my game I’m working on, when a line touches the circle sprite, it needs to suspend the circle in mid-air for 3 seconds before letting it go. So far, I have everything except for the collision detection between the line and the circle. The code relating to this is below:

The paint(Graphics g) method:


	public void paint(Graphics g) {
		super.paint(g);
                // Blah, blah, blah...
		g.drawImage(b.getBall(), b.getTileX() * 32, b.getTileY() * 32, null); // b is the Ball class
		g.setColor(Color.cyan);
		g.drawLine(mouseX, mouseY, 32, 32);
	}

The Ball class:


import java.awt.Image;
import java.util.Random;

import javax.swing.ImageIcon;

public class Ball {

	private int tileX, tileY;
	private Image ball;

	public Ball() {
		Random rand = new Random();
		int num = rand.nextInt(20);

		ImageIcon img = new ImageIcon("res/ball.png");
		ball = img.getImage();

		tileX = num;
		tileY = 2;
	}

	public Image getBall() {
		return ball;
	}

	public int getTileX() {
		return tileX;
	}

	public int getTileY() {
		return tileY;
	}

	public void down() {
		try {
			Thread.sleep(1);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		tileY++;
		try {
			Thread.sleep(700);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void hide() {
		tileX = 1;
		tileY = 1;
	}
}


In order to make the ball go down, I use this code


	if (level.getMap(b.getTileX(), b.getTileY()).equals("g")) {
			b.down();
		}

Does anyone have any suggestions how to make the collision detection for the ball and the line work? I’ve already tried


        	if (mouseX == b.getTileX() && mouseY == b.getTileY()) {
                // Do stuff.
		}

but it doesn’t work.

Thanks,

DarkCart