I have two problems; collision detection, and menu navigation. My collision system seems to work just fine until my object meet at certain points then they ride together. This is troublesome in a pong game.

For my collisions I'm inverting the X coordinate for the ball on intersection with the paddles. I'm doing this like so:

Declarations of Objects:

Rectangle ball;
        Rectangle playerOne;
        Rectangle playerTwo;
        Rectangle screen;

        Vector2 velocity = Vector2.Zero;

Code Snippet For Paddle Collision:

if (ball.Intersects(playerOne) || ball.Intersects(playerTwo))
                {
                    velocity.X = -velocity.X;
                    ballBounce.Play();
                }

Like I said, the error is just a bug that I can't figure out how to fix. With my difficulty on easy the ball will often hit the top or bottom of one of the paddles, then this begins a constant intersection between the ball and the paddle. Thus making it ride next to the paddle throughout the rest of run time.


Problem two is with menu navigation. I have four menu items, each of them are 2D textures in my game. So the navigation is mainly based on coordinates. That however is not the problem. The problem is with the integer value I'm using to navigate the menu with. Please note that all the syntax is for XNA Framework in C# but all the integer stuff is still the same as Visual C#.

There is a function being called each time the menu navigates; all this function does is move the corresponding menu item's X coordinate by an integer value of 5 to the right. The problem that I can see is, the game is running on an incredibly fast processing unit and the user doesn't have enough time to let of the A button in time for the integer to only climb once. (This is like a mouse down/up event handler in Visual C# forms applications.)

Code Snippet For Navigation:

if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
                    {
                        upDown--;

                        if (upDown <= 0)
                        {
                            upDown = 0;
                            difficultyRotation(0);
                        }

                        else if (upDown == 1)
                        {
                            difficultyRotation(1);
                        }

                        else if (upDown == 2)
                        {
                            difficultyRotation(2);
                        }
                    }

                    if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
                    {
                        upDown++;

                        if (upDown == 1)
                        {
                            difficultyRotation(1);
                        }

                        else if (upDown == 2)
                        {
                            difficultyRotation(2);
                        }

                        else if (upDown >= 3)
                        {
                            upDown = 3;
                            difficultyRotation(3);
                        }
                    }

I've always had a problem with this, and never could figure it out obviously. So any help with either topic is greatly appreciated.

I'm guessing no one here seems to have the energy or smarts either or, to even attempt to help me fix at least the integer problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.