Ok, I seemed to lose all motivation for Blitz ever since I got BMX, mostly because it was such a big change. So, I'm back at the beginning. So I figure I'd make pong. No types or anything, just pong. The only thing stopping me is collision. I'm not sure why the ball doesn't bounce off the paddle like it's supposed to. Take a look:
The code that is supposed to randomize the ball's starting direction fails to work as well. Any help would be appreciated. It seems I have yet to grasp BMX collision and random numbers.
Global paddle1,paddle2,ball1 Global py1,py2,bx,by,bsp,bdirx,bdiry Graphics 800,600,32,60 HideMouse() AutoMidHandle True SeedRnd MilliSecs() SetColor(255,255,255) py1=275 py2=275 bx=395 by=295 bsp=2 bdirx=Rnd(1,2) Select bdirx Case 1 bdirx=1 Case 2 bdirx=-1 End Select bdiry=Rnd(1,2) Select bdiry Case 1 bdiry=1 Case 2 bdiry=-1 End Select While Not KeyHit(KEY_ESCAPE) Game() Flip;Cls;FlushMem Wend Function Game() DrawRect(0,0,800,10) DrawRect(0,590,800,10) SetRotation(0) SetScale(1,1) SetColor(255,255,255) 'DrawImage(paddle1,0,py1) DrawRect(0,py1,10,75) DrawRect(790,py2,10,75) DrawRect(bx,by,10,10) CollideRect(0,py1,10,75,0,0,1) 'CollideRect(paddle2,790,py2,0,0,1) If KeyDown(KEY_UP) Then py1=py1-4 If KeyDown(KEY_DOWN) Then py1=py1+4 If by>py2 Then py2=py2+4 If by<py2 Then py2=py2-4 If py1<10 Then py1=10 If py1>515 Then py1=515 If py2<10 Then py2=10 If py2>515 Then py2=515 bx=bx+bdirx*bsp by=by+bdiry*bsp If by>580 Then bdiry=-1 If by<10 Then bdiry=1 If CollideRect(bx,by,10,10,0,1,0) Then bdirx=-bdirx DrawText("COLLISION!",200,300) EndIf End Function
The code that is supposed to randomize the ball's starting direction fails to work as well. Any help would be appreciated. It seems I have yet to grasp BMX collision and random numbers.