Why isn't my ball bouncing off the walls?
Please, I would be grateful for any help I recieve.
`set display and sync rate
set display mode 800,600,32
sync on
sync rate 40
hide mouse
start:
`define variables
ballx#=400 : ballxvel#=-5 : bally#=500 : ballyvel#=-6
batx#=mousex() : batxvel#=mousemovex()
wallx#=20 : wallx2#=780 : wally#=20 : wally2#=580
lives=4
time#=90
loser=0
winner=0
a1=timer()
`main loop
do
gosub move
gosub collision
gosub draw
loop
`************************************************************
collision:
`check for ball coliding with walls
if ballx#<=wallx# then ballxvel#=0+ballxvel#
if ballx#+10>=wallx2# then ballxvel#=0-ballxvel#
if bally#<=wally# then ballyvel#=0+ballyvel#
if bally#+10>=wally2# then ballyvel#=0-ballyvel#
`check for bat hitting ball
if bally#<550 and bally#+10>550 and ballx#<=batx#+60 and ballx#>=batx#
`reverse the x velocity
ballxvel#=0-ballxvel#
endif
`make sure bat stays on screen
if batx#<wallx#+5
batx#=wallx#+5 : batxvel#=0
endif
if batx#+60>wallx2#-5
batx#=wallx2#-65 : batxvel#=0
endif
return
`**************************************************************
draw:
line wallx#,wally#,wallx#,wally2#
line wallx#,wally#,wallx2#,wally#
line wallx2#,wally#,wallx2#,wally2#
line wallx#,wally2#,wallx2#,wally2#
line batx#,550,batx#+60,550
circle ballx#,bally#,10
sync
return
`**************************************************************
move:
cls
`get the x velocity of the bat and limit it to 50
batxvel#=mousemovex()
if batxvel#>50 then batxvel#=50
if batxvel#<-50 then batxvel#=-50
`move the bat and ball
batx#=batx#+batxvel#
ballx#=ballx#+ballxvel#
bally#=bally#+ballyvel#
cls
return