Hi Kopoku,
I haven't really had chance to review your code, however I can tell you how I approached this as far as I can remember (it was a while ago now). You can get at the source code for the flitter project here if you are interested:
https://github.com/Phillarby/Flitter. This is an eclipse workspace rather than a processing sketch, but the same principles can be applied directly in processing.
In any case, as far as I remember, a tweet is represented by a Message object - this holds various pieces of information received from the twitter api. This message object is then wrapped in a ShowStatus object, but you don't need to worry about this one too much as it is in turn wrapped in a TextFader object.
The TextFader object handles the positioning and drawing of the status. The local PVector in the TextFader allows each status being displayed to track it's own location information, so its a fairly trivial task to scan through the collection in each draw cycle and check this against the current mouse position to determine mouseover. This happens in the ProcessingTwitter.java class. This is really nothing more than a 2D particle system.
In your example, as you are holding x and y coordinates in your ball class you can perform a similar check, but it seems that the problem may be related to the fact you are creating a new ball object on each draw cycle which randomly repositions the ball? Can you try creating the ball object in the setup method, and just running an update on it to recalcualte the distance value in each draw cycle?
Something like this:
- void setup() {
- myBall = new Ball(random(width), random(height - 200));
- ...
- }
- void draw() {
- myball.update(mouseX, mousey);
- myBall.run();
- ...
- }
Good Luck
Phil