Sunday, March 28

Collision Game Programming

Public Class Form1
Dim life As Integer
Dim mythread1 As System.Threading.Thread
Dim mythread2 As System.Threading.Thread
Dim mythread3 As System.Threading.Thread
Public Sub panel1move()
Dim x1, y1, a2, b2 As Integer
Dim x11, y11, a22, b22 As Integer
Dim k As Integer
If k = 0 Then
For k = 0 To 975
x1 = Panel1.Location.X
a2 = Panel2.Location.X
y1 = Panel1.Location.Y
b2 = Panel2.Location.Y
x11 = x1 + 50
y11 = y1 + 50
a22 = a2 + 50
b22 = b2 + 50
If a22 > x1 And a2 < x11 And b22 > y1 And b2 < y11 Then
My.Computer.Audio.Play(My.Resources.FIRE1, AudioPlayMode.Background)
Label1.Text -= 1
mythread1.Abort()
mythread2.Abort()
Timer1.Enabled = False
Timer2.Enabled = False

Me.Refresh()
Panel2.Left = 387
Panel2.Top = 500
Panel3.Left = 0
Panel3.Top = 253
Panel1.Left = 0
Panel1.Top = 190
Me.Refresh()
Else
End If
Panel1.Left = k
System.Threading.Thread.Sleep(5)
Next
End If
End Sub
Public Sub panel3move()
Dim i As Integer
Dim x2, y2, x3, y3 As Integer
Dim x22, y22, x33, y33 As Integer

If i = 0 Then
For i = 0 To 925
x2 = Panel2.Location.X
x3 = Panel3.Location.X
y2 = Panel2.Location.Y
y3 = Panel3.Location.Y
x22 = x2 + 50
y22 = y2 + 50
x33 = x3 + 100
y33 = y3 + 50
If x22 > x3 And x2 < x33 And y22 > y3 And y2 < y33 Then
My.Computer.Audio.Play(My.Resources.FIRE1, AudioPlayMode.Background)
Label1.Text -= life
mythread1.Abort()
mythread2.Abort()
Timer1.Enabled = False
Timer2.Enabled = False

Panel2.Left = 387
Panel2.Top = 500
Panel3.Left = 0
Panel3.Top = 253
Panel1.Left = 0
Panel1.Top = 190
Me.Refresh()
Else
End If
Panel3.Left = i
System.Threading.Thread.Sleep(7)
Next
End If
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim x1, y1, x2, y2 As Integer
Dim x11, y11, x22, y22 As Integer
If e.KeyCode = Keys.S Then
Panel2.Top += 5
ElseIf e.KeyCode = Keys.W Then
Panel2.Top -= 5
ElseIf e.KeyCode = Keys.A Then
Panel2.Left -= 5
ElseIf e.KeyCode = Keys.D Then
Panel2.Left += 5
End If
Label13.Text = x1
Label14.Text = y1
Label15.Text = x2
Label16.Text = y2
Label17.Text = x11
Label18.Text = y11
Label19.Text = x22
Label20.Text = y22
If e.KeyCode = Keys.Enter Then
mythread1 = New System.Threading.Thread(AddressOf panel1move)
mythread1.Start()
Control.CheckForIllegalCrossThreadCalls = False
Timer1.Enabled = True
Timer2.Enabled = True
mythread2 = New System.Threading.Thread(AddressOf panel3move)
mythread2.Start()
Control.CheckForIllegalCrossThreadCalls = False
End If
If e.KeyCode = Keys.Escape Then
mythread1.Abort()
mythread2.Abort()
Timer1.Enabled = False
Timer2.Enabled = False
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Focus()
life = 2
Label1.Text = life
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
mythread1 = New System.Threading.Thread(AddressOf panel1move)
mythread1.Start()
Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
mythread2 = New System.Threading.Thread(AddressOf panel3move)
mythread2.Start()
Control.CheckForIllegalCrossThreadCalls = False
End Sub
End Class

No comments: