Imports System.Drawing.Drawing2D
Public Class Form1
Dim VSpeed As Single = 2
Dim HSpeed As Single = 2
Dim Score As Integer = 0
Dim x As Integer = 0
Dim x1 As Integer = 0
Dim y As Integer = 0
Dim y1 As Integer = 0
Dim SizeMode As String = "small"
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim graph As Graphics = e.Graphics
Dim pen As New Pen(Color.Black, 1)
'Прорисовка ракетки
Dim b As New SolidBrush(Color.DarkGoldenrod)
Dim point() As Point = {New Point(x + 2, y + 230), New Point(x + 102, y + 230),
New Point(x + 102, y + 240), New Point(x + 2, y + 240)}
Dim poin() As Point = {New Point(x + 3, y + 231), New Point(x + 102, y + 230),
New Point(x + 102, y + 240), New Point(x + 2, y + 240)}
graph.DrawPolygon(pen, point)
graph.FillPolygon(b, poin)
e.Graphics.DrawLine(Pens.Black, 360, 0, 360, 350)
'Прорисовка шарика
Dim b1 As New SolidBrush(Color.RosyBrown)
Dim point1() As Point = {New Point(x1 + 100, y1 + 200), New Point(x1 + 120, y1 + 200),
New Point(x1 + 120, y1 + 220), New Point(x1 + 100, y1 + 220)}
Dim point2() As Point = {New Point(x1 + 101, y1 + 201), New Point(x1 + 120, y1 + 200),
New Point(x1 + 120, y1 + 220), New Point(x1 + 100, y1 + 220)}
graph.DrawPolygon(pen, point1)
graph.FillPolygon(b1, point2)
'Прорисовка кирпичиков
Select Case SizeMode.ToLower
Case "small"
Dim lines() As String = IO.File.ReadAllLines("D:\card1.txt")
Dim st As Brick
For i = 0 To lines.Count - 1
For j = 0 To lines(i).Count - 1
If lines(i)(j) = "1" Then
st = New Brick(New Point(j * 35, i * 23))
End If
Next
Next
End Select
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Refresh()
''Движение шарика
'Check Left side of Screen
If (x1 + 100) < 0 Then
HSpeed = -HSpeed
End If
'Check Right side of Screen
If (x1 + 120) = 360 Then
HSpeed = -HSpeed
End If
x1 += HSpeed
'Check Top of Screen
If (y1 + 200) < 0 Then
VSpeed = -VSpeed
End If
'Check Bottom of Screen
If (y1 + 220) > Me.ClientRectangle.Height Then
Timer1.Enabled = False
End If
y1 += -VSpeed
'Столкновение с ракеткой
Dim C As Single = x1 + 110 'координаты центра шарика (x1+100)+(x1+120-(x1+100))/2
If C > (x + 2) And C < (x + 102) And VSpeed < 0 And
(y1 + 220) = (y + 230) And (y1 + 200) < (y + 230) Then
VSpeed = -VSpeed
Dim Offset As Single = C - (x + 52) 'смещение C-((x + 2) + (x + 102-(x+2) )/ 2)
Dim Ratio As Single = Offset / 50 'Offset/((x+102-(x+2)/2))
HSpeed += 2 * Ratio
End If
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
'Движение ракетки
If e.X < 270 Then
x = e.X - 10
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Width = 550
Me.Height = 290
End Sub
End Class
Public Class Brick
Public Sub New(ByVal pos As Point)
Dim p As New GraphicsPath
p.AddRectangle(New RectangleF(pos, New Size(30, 20)))
Dim br As New PathGradientBrush(p)
br.CenterColor = Color.White
br.CenterPoint = New Point(pos.X + 15, pos.Y + 10)
br.SurroundColors = {Color.BurlyWood}
Dim g As Graphics = Form1.CreateGraphics
g.CompositingQuality = CompositingQuality.HighQuality
g.SmoothingMode = SmoothingMode.HighQuality
g.DrawPath(Pens.Black, p)
g.FillPath(br, p)
End Sub
End Class