var GWIDTH:int = 800
var GHEIGHT:int = 600

var PlayerX:int = 30
var PlayerY:float = GHEIGHT/2 - 50
var PlayerPoints:int
var ComputerX:int = 740
var ComputerY:float = PlayerY
var ComputerPoints:int

var BallX:float = GWIDTH/2
var BallY:float = GHEIGHT/2
var BallYSpeed:float = Rnd( -1.5, 1.5 )
var BallXSpeed:float = Rnd( -1.5, 1.5 )

Graphics( GWIDTH, GHEIGHT )

While KeyHit( 27 ) = 0
	var Timespan:int = Millisecs()
	
	Cls()
	
	DrawRect( PlayerX, PlayerY, 30, 100 )
	DrawRect( ComputerX, ComputerY, 30, 100 )
	
	DrawOval( BallX, BallY, 30, 30 )
	
	DrawText( 100, 0, PlayerPoints )
	DrawText( 700, 0, ComputerPoints )
	
	If RectsOverlap( PlayerX, PlayerY, 30, 100, BallX, BallY, 30, 30 ) And BallXSpeed < 0 Then
		BallXSpeed = -BallXSpeed + Rnd( 0, 0.1 )
	ElseIf RectsOverlap( ComputerX, ComputerY, 30, 100, BallX, BallY, 30, 30 ) And BallXSpeed > 0 Then
		BallXSpeed = -BallXSpeed - Rnd( 0, 0.1 )
	EndIf

	If BallY < 0 Or BallY + 30 > GHEIGHT Then BallYSpeed = -BallYSpeed EndIf

	If BallX < 0 Or BallX + 30 > GWIDTH Then
		If BallX < 0 Then ComputerPoints = ComputerPoints + 1 Else PlayerPoints = PlayerPoints + 1 EndIf
		
		BallX = GWIDTH/2
		BallY = GHEIGHT/2
		
		BallYSpeed = Rnd( 0, 3 ) - 1.5
		BallXSpeed = Rnd( 0, 3 ) - 1.5
		
		Delay( 1000 )
	EndIf
	
	BallX = BallX + BallXSpeed*10
	BallY = BallY + BallYSpeed*10
	
	PlayerY = PlayerY + ( KeyDown( 40 ) - KeyDown( 38 ) )*5
	
	If BallY < ComputerY + 50 Then ComputerY = ComputerY - 2 Else ComputerY = ComputerY + 2 EndIf
	
	If PlayerY < 0 Then PlayerY = 0 ElseIf PlayerY + 100 > GHEIGHT Then PlayerY = GHEIGHT - 100 EndIf
	If ComputerY < 0 Then ComputerY = 0 ElseIf ComputerY + 100 > GHEIGHT Then ComputerY = GHEIGHT - 100 EndIf
	
	DrawText( 0, 0, Millisecs() - Timespan )
	
	Flip( 1 )
Wend

End()