Hiya,
I'm just trying to make a breakout clone at the moment and I have a problem with the ball and box collision. The first time the ball goes through the box, it stays but then when it bounces back it hides it correctly. The second box works fine. I'm not sure how that's possible with the code. Anyways, here's the portion that's messed up:
`Block Positions
DIM blockPos(2,2)
blockPos(1,1)=0
blockPos(1,2)=10
blockPos(2,1)=0
blockPos(2,2)=5
sync on
hide mouse
autocam off
gosub initialisation:
Do
gosub displayElements:
gosub playerControl:
gosub ball:
`Ball to box collision
For C = 10 to 11
If object collision(2,c)>0
Hide object c
set object collision off c
endif
Next C
sync
Loop
initialisation:
`camera
position camera 0,25,0
point camera 0,0,0
`Paddle
make object box 1,1,1,3
color object 1,rgb(155,0,0)
yrotate object 1,90
`ball
make object sphere 2,1
color object 2,rgb(0,0,255)
set object collision to spheres 2
`walls
make object box 50,1,1,32
position object 50,-17,0,0
set object collision to boxes 50
make object box 51,1,1,32
position object 51,17,0,0
set object collision to boxes 51
make object box 52,34,1,1
position object 52,0,0,15
set object collision to boxes 52
rem level
For t = 10 to 11
make object box t,1,1,3:color object t,rgb(0,255,0)
YRotate Object t,90
position object t,blockPos(t-9,1),0,blockPos(t-9,2)
set object collision to boxes t
Next t
`Necessary Variables
balla#=180
Score=0
return
displayElements:
set cursor 0,0
Print Score
return
playerControl:
rem paddle movement
IF rightkey()=1 and player1pos#<15 then player1pos#=player1pos#+0.5
IF leftkey()=1 and player1pos#>-15 then player1pos#=player1pos#-0.5
position object 1,player1pos#,0,-13
return
ball:
`Ball Movement
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)
`Bouncing
if ballx#>4 and ballx#<4 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>14 or ballz#<-12 then balla#=180-balla#
if ballx#>16 or ballx#<-16 then balla#=180-balla#
`Bouncing option 2, Collision with the walls NOT USED
` For W = 50 to 52
` If object collision(2,W)>0
` balla#=180-balla#
` endif
` Next W
rem MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
position object 2,ballx#,0,ballz#:yrotate object 2,balla#
return
Thanks!