Hey everybody. I'm new to the forum and have some experience with C#. I need to build a 2D box on screen using C# and have a ball that bounces around inside the box. I have to make a command key to stop and start the ball. I'm pretty lost here and don't even know where to start. Any advice would be helpful.

6 Years
Discussion Span
Last Post by skatamatic

What do you mean by bounce? The simplest form of making a ball bounce would be to invert the x or y speed each time it hits an edge (x for vertical collision, y for horizontal). For example:

Ball moving at 2 x pixels per tick and 5 y pixels per tick hits the bottom of the box (down and to the right), this bounces and is now 2 x pixels per tick and -5 y pixels per tick (up and to the right). Then it hits the right boundary and becomes -2, -5 (up and left).

This, of course, is not very realistic unless the environment is intended to be frictionless and free of gravity. I'll upload an old project I did that is pretty similar to this (only it incorporates gravity, friction, momentum, and elasticity as well and supports dragging the objects with a mouse, resizing selected shapes with the mouse wheel, and smashing them into eachother).


@skatamatic could not unzip or open your zip map. Using Windows 7 Home premium.

Try renaming it to .Rar and using WinRAR. This site wouldn't let me upload a .rar file so I just changed the extension and hope for the best :'(

Haha and maybe it's for the best that you can't - your math is likely superior to mine and you will probably find a lot of things that are wrong with it!

Update: I tried downloading it at work and have the same problem. I will re-upload it when I get the chance.

Edited by skatamatic: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.