Link to home
Start Free TrialLog in
Avatar of RobertoFreemano
RobertoFreemanoFlag for United Kingdom of Great Britain and Northern Ireland

asked on

vb.net drive game (basic) - help

Hi experts,

I'm trying to make a basic game (for fun) but im struggling with a few issues :(

1. winform
2. Label 1 (block), Label 2 (block), Label3 (car)

Label1 & 2 will start at top of screen (set width apart). The car (label3) is at bottom. I use a timer to scroll Label1 & 2 down... if collide with Label3 - lose a life. The aim is to drive Car between Label1 & 2 and not crash.

problems: What i'm struggling with is ...
* replicating Label1 & 2 to almost make a continuous scrolling road-edge
* keeping label1 /2 same width
* Random road genorator, but only by a little bit.

------------------------------------------------------------------------------
  *                                               *
*                                               *
*                                               *
 *                                               *
 *                                               *
  *                                               *
  *                                               *
  *                       Label3              *
------------------------------------------------------------------------------
I use * as the road edge example (label 1 & label2)
 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Top += 5
        Label2.Top += 5
        If Label1.Top >= +Height Then
            Label1.Top = Height
        ElseIf Label2.Top = Height Then
            Label2.Top = Height
        End If
        If Label1.Bounds.IntersectsWith(Label3.Bounds) Or Label2.Bounds.IntersectsWith(Label3.Bounds) Then
            Timer1.Enabled = False
            MsgBox("HIT")
        End If

        If Label1.Top = 300 Then
            Label4.Text = "something" ' repeat from top = 0
            start()
        End If
        If Label2.Top = 300 Then
            Label4.Text = "something" ' repeat from top = 0
            start()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        start()
    End Sub

    Function getRND(ByVal low As Integer, ByVal high As Integer)
        Dim num As Integer
        Dim random As New Random
        num = random.Next(low, high)
        Return num
    End Function

    Sub start()
        label1.top = 0
        Label1.Left = getRND(0, Me.Width)
        Label2.Top = 0
        Label2.Left = getRND(0, Me.Width)
    End Sub

Open in new window

Hope this makes sense :(
Thanks,
Roberto
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobertoFreemano

ASKER

Thanks Mike - once again, you save the day ;)