Hello, everyone.
I’m a novice programmer and I’m new to SDL and I’m having some trouble with
my Ping Pong game. The biggest issue being that the ball sometimes gets hit
back, but most of the time it just gets stuck behind the paddle.
I’m using SDL_HasIntersection(); to check if the ball (the Ball struct
contains a SDL_Rect) collides with the paddle (the Paddle struct contains a
SDL_Rect), if that happens, this method inside the Ball struct is called:
void Ball::Rebound(const SDL_Rect & paddle_rect, SDL_Rect & sadursme,
Mix_Chunk *& gLow)
{
SDL_IntersectRect(&getRect(), &paddle_rect, &sadursme);
float relX = (paddle_rect.x + 40) - sadursme.x;
float normX = relX / 40;
float angle = normX * MAX_ANGLE;
xVel = BALL_VEL * cos(angle);
yVel = BALL_VEL * sin(angle);
Mix_PlayChannel( -1, gLow, 0 );
}
I’m guessing the problem is that the ball actually goes inside the paddle
(this is when it gets stuck behind the paddle) and the Rebound method keeps
getting called, but I’ve yet come up with a solution.
Any help or advice is welcome!
Bernard–
View this message in context: http://sdl.5483.n7.nabble.com/Ping-Pong-The-ball-gets-stuck-behind-the-paddle-tp39741.html
Sent from the SDL mailing list archive at Nabble.com.