Hey guys just a quick question that i am sure someone can answer easy for me.
The past 3 days iv been working on getting collision detection working on the edge of a form as you will see from my code in a min i have a command button on a form that you can move with the arrow keys. Iv had sucsess with the top collision detection that one works and i got that working within an hour of trying to write the collision detection. How ever the bottem the left and the right seem un mathimatical to me as iv tryed adding and subtracting almost every combonation (Bottem,top,height,location,size) it is on a sizeable form so the collision detection must be flexable not set.
I have looked for ansers all over the internet and found a lot of good examples of set rectangle collision detection. Which i have tryed to modify to be flexable for what i want but it caused errors and one of them worked backwards... the button went off the screen but would not come back.
I have a good knolage of VB6 from when i was back in college and i remember one of my friends there made a collision detection statment that i used and tweeked for a few things but as iv found VB6 code won't fly with VB.Net.
Anyway here is my code have a look and please sugest something which is so simple i can slap myself in the face for not seeing it.
The past 3 days iv been working on getting collision detection working on the edge of a form as you will see from my code in a min i have a command button on a form that you can move with the arrow keys. Iv had sucsess with the top collision detection that one works and i got that working within an hour of trying to write the collision detection. How ever the bottem the left and the right seem un mathimatical to me as iv tryed adding and subtracting almost every combonation (Bottem,top,height,location,size) it is on a sizeable form so the collision detection must be flexable not set.
I have looked for ansers all over the internet and found a lot of good examples of set rectangle collision detection. Which i have tryed to modify to be flexable for what i want but it caused errors and one of them worked backwards... the button went off the screen but would not come back.
I have a good knolage of VB6 from when i was back in college and i remember one of my friends there made a collision detection statment that i used and tweeked for a few things but as iv found VB6 code won't fly with VB.Net.
Anyway here is my code have a look and please sugest something which is so simple i can slap myself in the face for not seeing it.
Private Sub BlackAndWhite_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Dim up As Boolean = False Dim left As Boolean = False Dim down As Boolean = False Dim right As Boolean = False If GetAsyncKeyState(Keys.Up) Then up = True If GetAsyncKeyState(Keys.Left) Then left = True If GetAsyncKeyState(Keys.Down) Then down = True If GetAsyncKeyState(Keys.Right) Then right = True If Me.Location.Y - Me.Location.Y = Button1.Location.Y Then up = False End If If up = True And right = True Then Button1.Left = Button1.Left + 10 Button1.Top = Button1.Top - 10 ElseIf up = True And left = True Then Button1.Left = Button1.Left - 10 Button1.Top = Button1.Top - 10 ElseIf down = True And right = True Then Button1.Left = Button1.Left + 10 Button1.Top = Button1.Top + 10 ElseIf down = True And left = True Then Button1.Left = Button1.Left - 10 Button1.Top = Button1.Top + 10 ElseIf right = True And up = False And down = False Then Button1.Left = Button1.Left + 10 ElseIf left = True And up = False And down = False Then Button1.Left = Button1.Left - 10 ElseIf up = True And right = False And left = False Then Button1.Top = Button1.Top - 10 ElseIf down = True And right = False And left = False Then Button1.Top = Button1.Top + 10 End If End Sub