Here is my code i know it somewhat messy but please help
vb
Public Class gameMain
#Region "Variables"
Private Const brickWidth As Integer = 160
Private Const brickHeight As Integer = 20
Private Const brickRows As Integer = 0
Private Const brickColumns As Integer = 0
Private brickArray(brickRows, brickColumns) As Rectangle
Private isBrickEnabled(brickRows, brickColumns) As Boolean
Private gamePaddle As Rectangle = New Rectangle(300, 434, 72, 10)
Private gameBall As Rectangle = New Rectangle(gamePaddle.X + 72 / 2 _
- (16 / 2), 432 - 16, 16, 16)
Private isBallGlued As Boolean = True
Dim speed As Single = 10
Dim xVel As Single = Math.Cos(speed) * speed
Dim yVel As Single = Math.Sin(speed) * speed
Dim counter As Integer = 4
Dim walls As Integer
Dim score As Integer = 0
#End Region
#Region "Load Game"
Private Sub gameMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
loadBricks()
End Sub
#End Region
#Region "Paint Event"
Private Sub gameMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
' Loop through all enabled bricks and display them.
For row As Integer = 0 To brickRows
For column As Integer = 0 To brickColumns
If isBrickEnabled(row, column) Then _
e.Graphics.FillRectangle(Brushes.Red, brickArray(row, column))
Next
Next
' Show the ball and the paddle.
e.Graphics.FillRectangle(Brushes.Black, gameBall)
e.Graphics.FillRectangle(Brushes.WhiteSmoke, gamePaddle)
End Sub
#End Region
#Region "Game Timer"
Private Sub tmrGame_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrgame.Tick
If Not isBallGlued Then _
gameBall.Location = New Point(gameBall.X + xVel, gameBall.Y + yVel)
' Check for top wall.
If gameBall.Location.Y < 0 Then
gameBall.Location = New Point(gameBall.Location.X, 0)
yVel = -yVel
walls += 1
End If
' Check for bottom wall (restart)
If gameBall.Location.Y - gameBall.Height > Me.Height Then
isBallGlued = True
gameBall.Location = New Point(gamePaddle.X + 72 / 2 _
- (gameBall.Width / 2), 432 - 16)
counter -= 1
End If
' Check for left wall.
If gameBall.Location.X < 0 Then
gameBall.Location = New Point(0, gameBall.Location.Y)
xVel = -xVel
walls += 1
End If
' Check for right wall.
If gameBall.Location.X + gameBall.Width > Me.Width Then
gameBall.Location = New Point(Me.Width - gameBall.Width, _
gameBall.Location.Y)
xVel = -xVel
walls += 1
End If
' Check for paddle.
If gameBall.IntersectsWith(gamePaddle) Then
gameBall.Location = New Point(gameBall.X, gamePaddle.Y - gameBall.Height)
yVel = -yVel
End If
'hits box
For rows As Integer = 0 To brickRows
For columns As Integer = 0 To brickColumns
If Not isBrickEnabled(rows, columns) Then Continue For
If gameBall.IntersectsWith(brickArray(rows, columns)) Then
'isBrickEnabled(rows, columns) = False
If gameBall.X + 10 < brickArray(rows, columns).X Or _
gameBall.X > brickArray(rows, columns).X + brickArray(rows, columns).Width _
Then
xVel = -xVel
Else
yVel = -yVel
End If
End If
Next
Next
' Check for end of game.
If counter = 0 Then
tmrgame.Stop()
Windows.Forms.Cursor.Show()
If MessageBox.Show("Would you like to play again?", "Play Again?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
walls = 0
isBallGlued = True
Windows.Forms.Cursor.Hide()
gameBall.Location = New Point(gamePaddle.X + 72 / 2 - (gameBall.Width / 2), _
432 - 16)
tmrgame.Start()
counter = 4
walls = 0
Else
Me.Close()
End If
End If
If walls = 0 Then
Me.lblbrick1.Visible = False
Me.lblbrick2.Visible = False
Me.lblbrick3.Visible = False
Me.lblbrick4.Visible = False
Me.lblbrick5.Visible = False
Me.lblbrick6.Visible = False
Me.lblbrick7.Visible = False
End If
Me.lblscore.Text = walls
If walls = 10 Then
Me.lblbrick1.Visible = True
End If
If walls = 15 Then
Me.lblbrick2.Visible = True
End If
If walls = 20 Then
Me.lblbrick3.Visible = True
End If
If walls = 25 Then
Me.lblbrick4.Visible = True
End If
If walls = 30 Then
Me.lblbrick5.Visible = True
End If
If walls = 35 Then
Me.lblbrick6.Visible = True
End If
If walls = 40 Then
Me.lblbrick7.Visible = True
End If
Me.lbllives.Text = "Bricks left " & counter - 1
Me.Refresh()
End Sub
#End Region
#Region "Set Up Bricks"
Sub loadBricks()
Dim xOffset As Integer = 250, yOffset As Integer = 200
For row As Integer = 0 To brickRows
For column As Integer = 0 To brickColumns
brickArray(row, column) = New Rectangle( _
xOffset, yOffset, brickWidth, brickHeight)
xOffset += brickWidth + 10
isBrickEnabled(row, column) = True
Next
yOffset += brickHeight + 10
xOffset = 75
Next
End Sub
#End Region
#Region "Move Paddle According to Mouse Position"
Private Sub gameMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.X > 0 And e.X < Me.Width - 72 Then _
gamePaddle.Location = New Point(e.X, gamePaddle.Y)
If isBallGlued Then
gameBall.Location = New Point(gamePaddle.X + 72 / 2 - (gameBall.Width / 2), _
432 - 16)
End If
End Sub
#End Region
#Region "Launch Ball"
Private Sub gameMain_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
If e.Button = Windows.Forms.MouseButtons.Left Then
' Launch the ball.
If isBallGlued Then
isBallGlued = False
End If
End If
End Sub
#End Region
#Region "Quit on Escape Key Press and Pause on P Key Press"
Private Sub gameMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
' Exit
If e.KeyCode = Keys.Escape Then Me.Close()
' Toggle Paused
If e.KeyCode = Keys.P Then _
If tmrgame.Enabled Then tmrgame.Stop() _
Else tmrgame.Start()
End Sub
#End Region
End Class