In Pong from the SDL manual, I was experiencing an issue where the paddle
movement was slower in one direction than the other.  The cause of this is
the way Perl and SDL handled the numbers passed.  Anything between 0 and 1
was floored to 0, but anything -1 and 0 was floored to -1.

Here is the fix that I used to correct the difference in velocities in the
Pong game:

sub round_down {
>     my $number = shift;
>     my $sign = ($number <=> 0);
>     my $roundNumber = ($sign * int(abs($number)));
>     return $roundNumber;
> }
>


I implemented the calls like this...

# handles the player's paddle movement
> $app->add_move_handler( sub {
>     my ($step, $app) = @_;
>     my $paddle = $player1->{paddle};
>     my $v_y = $player1->{v_y};
>
>     my $change = round_down($v_y * $step);
>     $paddle->y($paddle->y + $change);
> });
>

Hopefully, this will be useful in adding this functionality directly to the
SDLx::Rect.

Reply via email to