Click to See Complete Forum and Search --> : Java Bouncing Balls Features


a java student
April 3rd, 2008, 10:07 PM
I already have an applet that add a new bouncing ball each time I click the mouse inside the applet area. How do I implement the following features.

- As a ball moves, draw a solid-black oval shadow at the bottom of the applet.
- Bounce the balls off each other when they collide.

Please help. Thanks

ProgramThis
April 4th, 2008, 10:06 AM
Well, I don't know anything about applets, but you are going to need some type of method that is checked when the balls move around. I don't know what is driving your balls or how they are moving from one spot to another (and being redrawn) so I can't help you with that part just yet.

However, if it relatively easy to calculate when to balls (circles) collide. All you do is shoot a vector from the center of one ball to the next. If the length of the vector is <= 2*radius (assuming the balls have the same radius) then the balls have collided. If you are going to have a million balls running arround this is not going to be the best algorithm, but assuming there are few balls this is going to be the easiest to implement.