Hi, I am just beginning to learn DBPro and have been making this simple paddle game tonight. I had things working well but now the collision detection with the paddle is not working -- the ball just goes right through it. Can anyone notice what is wrong?
` set framerate
sync on
sync rate 60
` -------------------------------------------------------------
` INITIALIZE VARIABLES
` -------------------------------------------------------------
global x as integer = 320 `postions
global y as integer = 240
global paddle as integer = 320
global ballsize = 10 `object sizes
global speedx as integer = 3 `ball speed
global speedy as integer = -3
global alive as boolean = 1 `player status
global score as integer = 0 `player score
` -------------------------------------------------------------
` MAIN LOOP
` -------------------------------------------------------------
do
cls
` draw score
print "SCORE: ", score
DebugInfo()
` determine paddle position
paddle = MOUSEX()
if paddle < 50 then paddle = 50
if paddle > 590 then paddle = 590
` determine ball position
inc x, speedx
inc y, speedy
` collision
if alive = 1
` if ball hits wall, defelct
if x < ballsize or x > 640-ballsize
speedx = speedx * -1
endif
if y < ballsize or y > 480-ballsize
speedy = speedy * -1
endif
` if ball hits paddle, deflect
if y = 430 and x > paddle-50 and x < paddle+50
`speedx = speedx * -1
speedy = speedy * -1
endif
` if ball hits bottom, die
if y = 460
speedx = 0
speedy = 0
alive = 0
CENTER TEXT 320, 240, "YOU ARE DEAD!!!!"
CENTER TEXT 320, 250, "HIT SPACE TO CONTINUE"
endif
endif
if alive = 1
score = score+1
endif
` reset game
if alive = 0 and SPACEKEY() = 1
ResetGame()
endif
` draw ball
INK RGB(255,255,255), RGB(255,255,255)
SBFillCircle(x,y,ballsize)
` draw paddle
INK RGB(255,255,255), RGB(255,255,255)
box paddle-50, 440, paddle+50, 460
sync
loop
` -------------------------------------------------------------
` FUNCTIONS
` -------------------------------------------------------------
` function to draw a solid filled circle
` http://forum.thegamecreators.com/?m=forum_view&t=97808&b=10
function SBFillCircle( CX, CY, R )
sR = R*R
for i = 1 to R
h = sqrt( sR - i*i )
box CX - i, CY - h, CX + i, CY + h
next i
endfunction
` reset everything to starting position
function ResetGame()
` object positoons
x = 320
y = 240
` ball speed
speedx = 3
speedy = -3
` player life
alive = 1
` reset score
score = 0
endfunction
function DebugInfo()
print "var x: ", x
print "var y: ", y
print "var paddle: ", paddle
print "var alive: ", alive
endfunction
It is my first project so I am sure it is a little backwards! Any help would be appreciated.
badrock