0
votes

When I run this, After the ball comes close to the left paddle it will either bounce a quarter screen early, hit the paddle then after the ball moves away just a bit, it starts bouncing back and forth as if it was hitting a wall. Can you see what I'm doing wrong (Or not doing that I should be)?

ballPos is the Vector2 value for the balls position. paddleStaticPos.X is the X position for the paddle (located 5 off of the left wall) paddlePos.X is the Y value for the left paddle.

I know I should have used the vector values for the left and right paddles separately rather than binding the, but I don't have time to fix it anymore. Here is the code:

            if (ballPos.X <= paddleStaticPos.X + 15)
            {
                if (ballPos.Y <= paddlePos.X + 25 && ballPos.Y >= paddlePos.X)
                {
                    gameStartpaddleHit = true;
                    lastPaddleHitLeft = true;
                    ballLeft = ballLeft * -1;
                    ballUp = ballUp * -1;
                    soundEffect[0].Play();
                }
            }
            //Sedond Sector(26-100[MIRROR EFFECT])
            int tmp2=ballLeft;
            if (ballPos.X <= paddleStaticPos.X + 15)
            {
                if (ballPos.Y <= paddlePos.X + 99 && ballPos.Y >= paddlePos.X + 26)
                {
                    gameStartpaddleHit = true;
                    lastPaddleHitLeft = true;
                    ballLeft = tmp2 * -1;
                    soundEffect[0].Play();
                }
            }


            //Third Sector(101-125[SHARP ANGLE DEFLECT])
            if (ballPos.X <= paddlePos.X + 15)
            {
                if (ballPos.Y <= paddlePos.X + 125 && ballPos.Y >= paddlePos.X + 100)
                {
                    gameStartpaddleHit = true;
                    lastPaddleHitLeft = true;
                    ballLeft = ballLeft * -1;
                    ballUp = ballUp * -1;
                    soundEffect[0].Play();
                }
            }

If you prefer pastebin: http://pastebin.com/K0PitFcQ

1

1 Answers

0
votes

You are testing ballPos Y against paddlePos X

if (ballPos.Y <= paddlePos.X + 25 && ballPos.Y >= paddlePos.X)

Shouldn't it be this?

if (ballPos.Y <= paddlePos.Y + 25 && ballPos.Y >= paddlePos.Y)