i am currently making a game for my VB class and i am trying to make some boundary code. I have done everything. i've asked people my friends for help and we can't figure it out. if anyone could give me some clues to get started that would be great. I need the game to be over when two labels make contact with each other. The help would be greatly appreciated. I am only doing this as a last resort. Could someone plz help me?!

Recommended Answers

All 4 Replies

Here is some code I just made for you. Just add this to a timer and set the interval to 1. It should do the job. Read the code.. you'll see its very simple. Dont forget to change the label names for yours.

If (Label1.Left >= Label2.Left And Label1.Left <= Label2.Left + Label2.Width) Or _
        (Label1.Left + Label1.Width >= Label2.Left And Label1.Left + Label1.Width <= Label2.Left + Label2.Width) Then
            If (Label1.Top >= Label2.Top And Label1.Top <= Label2.Top + Label2.Height) Or _
                    (Label1.Top + Label1.Height >= Label2.Top And Label1.Top + Label1.Height <= Label2.Top + Label2.Height) Then
                    'do some stuff here
            End If
End If

If you need further assistance just drop by. I have made a small app in VB.Net with this code and a moving label using arrow keys. If you want it just ask.


commented: Now that's what I'm talking about... You went so far as to actually build a sample app to help this person. Outstanding +1

Here is the sample app you asked for. If you have any more problems just explain them here.

...Oh yea and for your other question, I will help you with it friday or this weekend. And post your questions in the forum instead of asking directly through Private Messaging, thx.

I used the code for the boundary stuff and i put a messagebox in there if the two labels come in contact with each other, but when they do the messagebox just keeps reappearing like an infinite loop. Could you please take a look at this

Well, when the labels colide, you should temporarily disable the timer with the code in it or you will press ok, and the code will check if the labels are still on top of each other, and of course, another msgbox will appear.

YourTimerName.Enabled = False
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.