filmov
tv
how to make an EASY car game in visual basic 2010 Step by Step
Показать описание
I really recommend you to buy the new amazon echo product from the amazon site through this link:
hello guys today I will show you how to make a car game .
this is the code :
Public Class Form1
Dim road(6) As PictureBox
Dim cars(4) As PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Stop()
Timer2.Stop()
Timer3.Stop()
road(1) = PictureBox1
road(2) = PictureBox2
road(3) = PictureBox3
road(4) = PictureBox4
road(5) = PictureBox5
road(6) = PictureBox6
cars(1) = PictureBox8
cars(2) = PictureBox9
cars(3) = PictureBox10
cars(4) = PictureBox11
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For x = 1 To 6
road(x).Top += 15
If road(x).Top = Me.Height Then
road(x).Top = -road(x).Height
End If
Next
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Left
PictureBox7.Left -= 5
Case Keys.Right
PictureBox7.Left += 5
End Select
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
For y = 1 To 4
cars(y).Top += 10
If cars(y).Top = Me.Height Then
cars(y).Top = -(Rnd() * 10)
End If
If PictureBox7.Bounds.IntersectsWith(cars(y).Bounds) Then
Timer1.Stop()
Timer2.Stop()
Timer3.Stop()
MsgBox("game over")
End If
Next
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Label1.Text = Label1.Text + 0.1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
Timer2.Start()
Timer3.Start()
Button1.Enabled = False
Button1.Visible = False
End Sub
End Class
hello guys today I will show you how to make a car game .
this is the code :
Public Class Form1
Dim road(6) As PictureBox
Dim cars(4) As PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Stop()
Timer2.Stop()
Timer3.Stop()
road(1) = PictureBox1
road(2) = PictureBox2
road(3) = PictureBox3
road(4) = PictureBox4
road(5) = PictureBox5
road(6) = PictureBox6
cars(1) = PictureBox8
cars(2) = PictureBox9
cars(3) = PictureBox10
cars(4) = PictureBox11
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For x = 1 To 6
road(x).Top += 15
If road(x).Top = Me.Height Then
road(x).Top = -road(x).Height
End If
Next
End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Left
PictureBox7.Left -= 5
Case Keys.Right
PictureBox7.Left += 5
End Select
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
For y = 1 To 4
cars(y).Top += 10
If cars(y).Top = Me.Height Then
cars(y).Top = -(Rnd() * 10)
End If
If PictureBox7.Bounds.IntersectsWith(cars(y).Bounds) Then
Timer1.Stop()
Timer2.Stop()
Timer3.Stop()
MsgBox("game over")
End If
Next
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Label1.Text = Label1.Text + 0.1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
Timer2.Start()
Timer3.Start()
Button1.Enabled = False
Button1.Visible = False
End Sub
End Class
Комментарии