in reply to Movement handlers in SDL

See my reply to your previous post Re: More Pong in SDL.
$paddle->y is a 'getter' method to get the y position of the $paddle object.
$paddle->y(value) is a 'setter' method to set the y position of the $paddle object.

So the code $paddle->y( $paddle->y + ( $v_y * $step ) )increment the y position by the velocity * step

Also there is an error in line 155.

#return of $A->left > $B->right; return if $A->left > $B->right;
poj

Replies are listed 'Best First'.
Re^2: Movement handlers in SDL
by drose2211 (Sexton) on Dec 05, 2017 at 01:19 UTC

    Sorry for not noticing your previous reply. If I had been a bit more observant I could have avoided that. Adding the + to both paddles placed them in the center of the screen as well as allowing them to move smoothly back and forth. Now the issue I am having is that the ball hits the paddle, but does not bounce back towards the other side. Alls it does is sit in the position where it hit the paddle. I am assuming this is some issue in the two elsif statements that check for collision with the paddles. Or possibly something wrong inside the subroutine definition? I fixed the 'return if' statement so that's not it. UPDATE...It was in the $player1 elsif statement. the two lines needed to be switched to match $player2 elsif statement.