When the ball is about to hit the paddle, move the paddle with the mouse to hit the ball in the direction you want it to go or to slow it down from the direction it is traveling by hitting it the opposite way.
bspd is the ball speed in either x or y direction
bdiry is the current y direction: positive or negative
I originally was controlling both directions with bdirx and bdiry, but decided I would just use speed for the x direction and have a negative or positive value so direction is already accounted for. I could've done the same for y, but left the code the way I originally wrote it in that regard.
rem paddle movement example
rem by latch
rem 08/05/2009
set display mode 800,600,32
sync on
sync rate 60
hide mouse
rem paddle
ink rgb(255,0,0),0
box 9,0,65,20
for r=0 to 9
circle 10,10,r
circle 10,9,r
circle 64,10,r
circle 64,9,r
next r
get image 1,1,0,74,20
sync
rem setup paddle
sprite 1,screen width()/2-38, screen height()-22,1
set sprite 1,0,1
px=sprite x(1)
py=sprite y(1)
rem setup ball
cls 0
cinc#=255/16.0
for r=0 to 15
c=255-(r*cinc#)
ink rgb(c,c,c),0
circle 16,16,r
circle 16,15,r
next r
get image 2,0,0,32,32
sync
bspdx=5
bspdy=5
bdirx=1
bdiry=-1
sprite 2,screen width()/2,screen height()/2,2
set sprite 2,0,1
bx=sprite x(2)
by=sprite y(2)
do
cls 128
gosub _move_paddle
gosub _move_ball
sync
`wait key
loop
_move_paddle:
oldpx=px
inc px,mousemovex()
sprite 1,px,py,1
return
_move_ball:
oldbx=bx
oldby=by
rem check for collision with the walls
rem walls
if bx <= 0 or bx+32 >= screen width() then bspdx=0-bspdx
rem floor/ceiling
if by <= 0 or by+32 >= screen height() then bdiry=0-bdiry
rem check for collision with paddle
if sprite hit(2,1)
xinc=(px-oldpx)
rem emphasize ball xdirection by paddle movement
if abs(xinc) > 5 then xinc=((abs(xinc))/xinc)*5
bspdx=bspdx+xinc
bdiry=0-bdiry
endif
inc bx,bspdx
inc by,bspdy*bdiry
sprite 2,bx,by,2
return
Enjoy your day.