CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2008
    Posts
    23

    Question Java Bouncing Balls Features

    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

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Java Bouncing Balls Features

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured