pong
BlitzMax Forums/BlitzMax Beginners Area/pong
| ||
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. |
| ||
You need to write the two bats to the collision mask otherwise you will have nothing to check the ball against. |
| ||
Here is a test that I did when I first started out with BlitzMax. Graphics 640, 480, 0 SetBlend ALPHABLEND player1_y# = 240 player1_speed# = 0.0 player2_y = 240 ball_x# = 320 ball_y# = 240 startingAngle = Rand( 45, 135 ) ball_xSpeed# = Sin( startingAngle )*3 ball_ySpeed# = Cos( startingAngle )*3 While Not KeyHit( KEY_ESCAPE ) If KeyDown( KEY_UP ) Then player1_speed# :- 0.8 If KeyDown( KEY_DOWN ) Then player1_speed# :+ 0.8 player1_speed# :* 0.9 player1_y# :+ player1_speed# player2_y = ball_y# If player1_y < 50 Then player1_y = 50 If player1_y > 430 Then player1_y = 430 If player2_y < 50 Then player2_y = 50 If player2_y > 430 Then player2_y = 430 If ball_x# <= 18 Then If ball_y# < player1_y+50 And ball_y# > player1_y-50 Then ball_xSpeed# = -ball_xSpeed# ball_ySpeed# :+ player1_speed#/4 End If ElseIf ball_x >= 622 Then If ball_y# < player2_y+50 And ball_y# > player2_y-50 Then ball_xSpeed# = -ball_xSpeed# End If End If If ball_y# <= 8 Or ball_y >= 472 Then ball_ySpeed# = -ball_ySpeed# End If ball_x# :+ ball_xSpeed# ball_y# :+ ball_ySpeed# Cls DrawRect 0, player1_y-50, 10, 100 DrawRect 630, player2_y-50, 10, 100 DrawOval ball_x#-8, ball_y#-8, 16, 16 DrawLine 320, 0, 320, 480 Flip Wend End |
| ||
Purt: That works, but it seems to be veeerrry laggy now.. Something to do with the collisions being called over and over again in the loop or something? Daniel: Hey, that's realy cool! I like how smooth it is, thanks. I think I will study that. |
| ||
Just stuck a ResetCollisions() in, seems okay now. *EDIT* oh yeah, have a look a this to see whats happening with rnd() Repeat Print Rnd(1,2) 'Print Int(Rnd(1,2)) 'Print Int(Rnd(1,3)) Until KeyHit(KEY_ESCAPE) |
| ||
Thanks Papa and Purt. I think I can take it from here. :) |