pong

BlitzMax Forums/BlitzMax Beginners Area/pong

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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