Hiya,
I've just got a few problems that I can't seem to get working properly in breakout. I've been using the pong tutorial by chris k as a basis, but I'm stuck. The current problems I can't get working are the collision with the left and right sides of the arena and the ball bouncing, which is basically most of the game... The ball still won't go past the paddle, I don't think I understand chris's version of the code that well... When the ball is within a certain range of the paddle, you are supposed to be able to move the paddle and thus move the ball, but the code is very flaky that I have. I'm not sure what all the problems are with that. Thanks for any help anyone can give me on any of my problems.
Here's the code:
`Block Positions
DIM blockPos(6,2)
blockPos(1,1)=-10
blockPos(1,2)=10
blockPos(2,1)=-10
blockPos(2,2)=5
blockPos(3,1)=-10
blockPos(3,2)=0
blockPos(4,1)=10
blockPos(4,2)=10
blockPos(5,1)=10
blockPos(5,2)=5
blockPos(6,1)=10
blockPos(6,2)=0
sync on
sync rate 40
hide mouse
autocam off
backdrop on
color backdrop rgb(0,0,0)
gosub initialisation:
Do
gosub displayElements:
gosub playerControl:
gosub ball:
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 15
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 65,20
Print "Score: ", Score
fps=Screen Fps()
print fps
print statistic(1)
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
if rightkey()=1 and ballz#>-11.5 and ballz#<-11 then balla#=balla#-8
if leftkey()=1 and ballz#>-11.5 and ballz#<-11 then balla#=balla#+8
return
ball:
`Ball Movement
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)
`Bouncing
if ballz#>16 and ballz#<16 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballz#>14 or ballz#<-12 then balla#=180-balla#
if ballx#>15.5 or ballx#<-15.5 then balla#=180-balla#
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#
`Ball to box collision
For C = 10 to 15
If object collision(2,0)=c
balla#=wrapvalue(balla#+180)
Hide object C
set object collision off C
inc score, 50
endif
Next C
return