The document outlines the code for a car racing game implemented in Visual Basic. It includes functionalities for moving the player's car, adjusting speed based on score, and detecting collisions with other race cars. The game also features a scoring system and a method to restart the game after a collision occurs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
10 views4 pages
OUTPUT
The document outlines the code for a car racing game implemented in Visual Basic. It includes functionalities for moving the player's car, adjusting speed based on score, and detecting collisions with other race cars. The game also features a scoring system and a method to restart the game after a collision occurs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
CAR GAME
Public Class Form1
Dim speed As Integer Dim road(7) As PictureBox Dim score As Integer = 0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load speed = 2 road(0) = PictureBox1 road(1) = PictureBox2 road(2) = PictureBox3 road(3) = PictureBox4 road(4) = PictureBox5 road(5) = PictureBox6 End Sub
Private Sub roadmover_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles roadmover.Tick For x As Integer = 0 To 5 road(x).Top += speed If road(x).Top >= Me.Height Then road(x).Top = -road(x).Height End If Next
If score > 3 And score < 8 Then
speed = 5 End If If score > 15 And score < 20 Then speed = 7 End If If score > 30 And score < 40 Then speed = 9 End If If score > 100 Then speed = 10 End If
Label2.Text = "Speed" & speed
If (car.Bounds.IntersectsWith(race1.Bounds)) Then endgame() End If If (car.Bounds.IntersectsWith(race2.Bounds)) Then endgame() End If If (car.Bounds.IntersectsWith(race3.Bounds)) Then endgame() End If End Sub
Private Sub endgame()
Button1.Visible = True Label3.Visible = True roadmover.Stop() Racermover1.Stop() Racermover2.Stop() Racermover3.Stop() End Sub
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Right Then rightside.Start() End If
If e.KeyCode = Keys.Left Then
leftside.Start() End If End Sub
Private Sub rightside_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles rightside.Tick If (car.Location.X < 420) Then car.Left += 2 End If End Sub
Private Sub leftside_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles leftside.Tick If (car.Location.X < 450) Then car.Left -= 2 End If End Sub
Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp rightside.Stop() leftside.Stop() End Sub
Private Sub Racermover1_Tick(ByVal sender As System.Object, ByVal e As