Hi guys
I've been following through a tutorial in a book to create a basic pong clone.
I've followed the code exactly, however the collision detection when the ball hits the paddle is not working, can anyone help please?
ballx as integer = 320
bally as integer = 240
speedx as integer = -2
speedy as integer = 1
px1 as integer = 600
py1 as integer = 240
px2 as integer = 20
py2 as integer = 240
score1 as integer = 0
score2 as integer = 0
rem slow down the game
sync on
sync rate 40
do
cls
if shiftkey()
dec py2, 2
if py2 < 0 then py2 = 0
endif
if controlkey()
inc py2, 2
if py2 > 470 then py2 = 470
endif
if upkey()
dec py1, 2
if py1 < 0 then py1 = 0
endif
if downkey()
inc py1, 2
if py1 > 470 then py1 = 470
endif
rem move the ball
inc ballx, speedx
inc bally, speedy
rem bounce ball off top and bottom of screen
if bally < 0 or bally > 470 then speedy = speedy * -1
rem see if left player misses the ball
rem if so player 2 scores, reset ball
if ballx < 0
inc score2, 1
ballx = 320
bally = 240
speedx = 2
sleep 500
endif
rem see if right player misses the ball
rem if so player 1 scores, reset ball
if ballx > 630
inc score1, 1
ballx = 320
bally = 240
speedx = -2
sleep 500
endif
rem draw the ball
circle ballx,bally,10
rem draw the paddles
box px1, py1, px1 + 16, py1 + 64
box px2, py2, px2 + 16, py2 + 64
rem lets see if the ball has hit the paddle
if point(ballx + 5, bally + 5) > 0
speedx = speedx * -1
endif
rem print the scores
text 0,0, "Score" + str$(score1)
text 550,0, "Score" + str$(score2)
rem draw the screen
sync
loop